Change in Physical State. Heat also affects how molecules interact with each other. Heating a solid above a certain temperature will cause it to melt to form a liquid; further heating causes this liquid to boil to form a vapor.
When water is in its solid state (ice) , the water molecules are packed close together preventing it from changing shape. Ice has a very regular pattern with the molecules rigidly apart from one another connected by the hydrogen bonds that form a crystalline lattice.
But back to your question - it's not why can water turn into ice (solid), vapour (gas) and liquid again, these are just changes of physical states (they are all still water just in different forms). The role of temperature is just a measure of how much vibrational energy that is possessed by the water molecules.