The particles in a substance have kinetic energy because they move, and potential energy because of the forces between them. The total of these two energies is the internal energy of the system. It is the energy stored within the system.
Heating a system transfers energy to it, so its internal energy increases. If the substance is not changing state, the energy increases the average kinetic energy of the particles. They vibrate or move faster, and the temperature rises.
During a change of state the energy does something different. When a solid melts or a liquid boils, the energy is used to pull the particles apart against the forces between them. This increases their potential energy, but not their kinetic energy. So the temperature stays constant while the change of state happens, even though heating continues. When a gas condenses or a liquid freezes, the potential energy decreases and energy is released.