This explains how to make one, but not really how it works. It’s actually even simpler than that for how.
You remember from physics class how hot things expand (get bigger), and cold thing contract (get smaller)? It works the other way too… make something smaller, by compressing (squeezing) it, and it’ll get hotter. Make something bigger by expanding (stretching) it, and it’ll get cooler. And the key thing is, it does this increase and decrease by basically a set amount.
Another thing you may realize is that temperatures tend to equalize. But a hot thing in the cool air, and the hot thing will get cooler and the air will get warmer. If you put an air-temperature thing in air, neither will change, because both are at the same temperature already.
These two facts are all you need to know to understand a refrigerator.
Step one: take a liquid or gas or something, and equalize it with the temperature in the box.
Step two: take that liquid or gas out of the box, then squeeze it hard so that it heats up. Now, let the hotter liquid or gas equalize with the air OUTSIDE the box, getting cooler.
Step three: stop squeezing the liquid or gas so that it cools back down… but we already lost some heat to the air when it was hotter! So when it cools down, it’ll cool down to LOWER than before.
Now, when we repeat the steps, step one is to equalize with the temperature inside the box. This will lower the temperature in the box!
And that’s how it works. Two physics principles and a little bit of engineering.