The first point to understand about refrigeration theory is that heat is energy, and it can be made to move. If enough heat is removed from a glass of water, the water will freeze to ice. When that heat is allowed to move back into the ice, the ice will melt.
Heat has its own laws, called the laws of thermodynamics.