How do phase changes occur on a molecular level?
Particle speed increases/decreases causing attraction to break/strengthen respectively. This leads to a phase change.
The phase changes are due to the particles' behaviour.
Ultimately, when a particle gains energy (AKA increase temperature), the atomic attraction becomes weaker and causes a change to the matter.
This results in a change from solid -> liquid -> gas.
The opposite occurs for gas -> liquid -> solid.
=> The particles lose energy (AKA becomes cooler).
Hope this helps :)