This will be with large volume machines in mind but applies to any dehumidifier and the cooling system is basically the same as common refrigeration.
A power source directs energy into a motor which adds kinetic energy to blades/paddles that push air into a chamber and over/against a high surface area of cold thermal conductor (a coil of copper/aluminum filled with coolant) reduces kinetic energy/heat in the air and water molecules and condensation of the water vapor to liquid which drains down in a isolation reservoir or drainage system with the dry gas molecules expelled at the other end through an exhaust. The key source that causes this in not magic but rather a thermodynamic law-abiding compressor powered by an electric motor which cycles a permanent/housed gas volume (it’s not the surrounding air but a factory sealed gas, such as a hydrofluorocarbon efficient in pressure-temperature change) which is pushed as several chunks into a chamber much smaller in volume than these combined chunks via a one-way valve which makes that volume of gas relatively much hotter as the kinetic energy conserves but collisions increase in less space, the hot gas is released to continue through the coil and expand into the greater volume resulting in a reversal of kinetic energy/volume and becoming the coolant for the initial coil I described as a vapor condenser.
The initial kinetic energy of the gas before the machine started is conserved and so it’s just manipulated through the application of mechanical forces to be hot and cold when out and in.
The orientation of the system is necessarily that the hot part is on the back for increased cooling from air and dissipation away from the condensation area and heat intolerant parts. The cold part clearly needs to be in containment so moist are is forced to precipitate and not be mixed with warm moist air and re-heat.
The motor and compressor are on the bottom due to balance and mobility but most critically so a natural pressure cycle helps feed the compressor since the hot gas will rise up and away then cool as it u-turns and heads down as a dense gas or liquid to the compressor intake. The turn itself doesn’t cool it any it’s just where an engineer figured it should turn for optimal flow of hot-cool-cold gas.
I hope that overs everything you could want to know.