When the total amount of energy in a substance reaches a certain point, it changes state. For example, when the kinetic energy in a substance is removed by cooling it (thus spreading out the kinetic energy through thermal energy in attempt to heat up the cold) and the molecules slow down to the point they change phases. Also, when put under high pressure, molecules move faster, causing them to heat up, and vice versa.
Hope this helps!