The inside of a refrigerator is a closed space.
Behind or below the refrigerator there are coils - usually copper tubing containing a fluid that can be compressed to a liquid, or expanded to a gas. And there is a compressor. That is a pump that moves the fluid and also compresses it. The fluid is called a refrigerant.
When the refrigerant is compressed, it releases heat. That is why the coils outside the refrigerator are warm. Then the refrigerant, in liquid form, is sent back into the coils inside the refrigerator, where there is more space. The refrigerant expands to a gas, absorbing heat from the air in the refrigerator. Then it is pumped out again, and releases the heat outside the refrigerator. So the whole refrigeration system picks up heat inside the refrigerator and moves it outside, over and over.
A thermostat measures temperature and controls the compressor pump. The thermostat shuts the pump down before the refrigerator gets too cold, and starts it up again before the refrigerator gets too warm. That keeps the inside of the refrigerator steadily cold.