Chlorine (Cl2) is a gas at room temperature, but sodium chloride(NaCl) is a solid at room temperature. The melting/boiling point of a substance determines what state of matter it takes at a certain temperature. In Cl2 there are covalent bonds between the atoms forming simple molecules.
The properties of a compound at most times are entirely different than that of its respective reacted elements.
Chlorine molecule contains covalent bond between like atoms, formed as a result of sharing the electron pair. The force of attraction between these Cl2 molecules is weak. So it requires less energy to break their attractive forces, even at temperatures lower than that of the room conditions.
In case of sodium chloride compound, it contains positively charged sodium(Na+) and negatively charged chloride(Cl−) ions bound by very strong electrostatic force of attraction(ionic bond). It forms a giant lattice due to the strong ionic force of attraction between the similar molecules,(NaCl - NaCl attraction is strong) so they require huge amount of energy(at higher temperature) to break those forces.
Stronger the lattice higher the boiling point and Cl ha no lattice