The logic behind this is the knowledge of density of a gas at different temperatures.
Here is why freezer is placed at the top.
Gases at higher temperature have lower density, so they tend to settle at lower levels.
In refrigerator, the process starts from "compressor" which has ammonia
The liquid ammonia which is circulating ,abosorbs heat from refrigerator, and gets evoporated.
Now,this warm gas has higher temperature hence less dense, so it moves up to freezer which cold.
Here gas cools down, it's density increases and moves down to compressor
Compressor again compresses gas,it's temperature increases and looses heat to surroundings.