I have two Cat 5 cables pre-installed in the walls. I need to connect two rooms, in which each room has its own set of in-wall Cat 5 cables and a slots. Does it work to use a Cat 6 cable to connect the two rooms (using the slot in each room)?
Yes. Cat-6 cable requirements are a superset of Cat-5e - there's no problem.
Note that a length of Cat-6 doesn't make the full path Cat-6. ;-)
A short answer is absolutely; CAT6 is backwards compatible to CAT5.
The full answer; since CAT ANSI ratings for cables describe the quality of the wires and speed/attenuation rating of the cable, and NOT the connectors and pin-out of the cables, "Not necessarily".
It sounds like you are using cables with RJ-45 connectors. Usually people refer to these cables as "Ethernet" cables, although Ethernet is a layer 2 networking protocol and not a type of cable. I'm going to infer that you have networking jacks in each room with a punchdown block for these RJ-45 connectors, and that they are 8p-8c. Assuming all this, because your question was about the rating of the wires within the cables, and not in regards to the pin-out on the ends of the cables, the correct answer is "Maybe!". For example, if the jacks in the wall are pinned out in in a non-TIA configuration (neither 568A or 568B), you will not be getting a usable signal over the connection. While an unlikely scenario it is certainly possible; it is worth understanding the CAT rating of the cable is not the only relevant factor in determining your cabling success or failure.