Energy has to be added to break the water bonds allowing the water molecule's to break free, the water vapour molecules can only exist in this higher energy state.
When the process is reversed this energy is released.
In old units - it takes about 970 BTU to evaporate 1 pound of water, depends on the ambient temperature ( 1 pound of water is 1/10th of a gallon)
A dehumidifier is a heat pump, the motor uses energy to compress the refrigerant until it is a liquid making hot in the process, it has changed state, the refrigerant is then passed into a cooler to cool down to near ambient temp, this heat returns to the room.
Next, the refrigerant is expanded through a fine nozzle, causing the resultant gas to be cold because energy was needed for the change of state, also the expansion of the gas causes some cooling.
The cold gas passes into the condenser (the cold end of the heat pump), humid air is blown over the outside of the condenser, and the condenser transfers heat into the gas.
This heat is made up of heat from the ambient air, and water vapour, plus the latent heat (the energy that enabled the water to exist in a gaseous form).
The refrigerant gas now contains the total energy air + latent heat.
This energy is subsequently released in the cooler next time round the cycle.
Of course there can only be energy gain when there is water vapour to be removed.