Been a while since I did fluid mechanics, so where to begin to explain your question? Hmmm…

Let’s start with dimensional analysis. If you multiply pressure times volume, what units do you get? Pressure is force over area, or N/m^2. Volume is m^3, and the product of pressure and volume is N*m which is the same units as work!

In fact, chemists often write work done as the pressure times the change in volume for a liquid. Engineers know better and correctly write the change in work as the pressure times the change in volume multiplied by the volume times the change in pressure.

In fact, a fluid does work whenever it changes volume and/or pressure. Is this related to temperature change? Of course. We know for gases that pressure is proportional to temperature, for example, and all that stuff about Boyle’s Law and Charles’ Law etc. applies. But there is also a relation for liquids and ice as well which can be interpreted from the appropriate “phase diagrams” (graphs of V vs. T, P vs. V, P vs. T, or all three) for the given subject, i.e. ice and water.

As for energy, heat loss with a change in temperature when not at the freezing point is given by E=m*c*(dT) where c is the specific heat cvapacity and dT is the change in temperature for an object of mass m. At the actual freezing point, the temperature of ice stays at 0 degC but there is energy needed to change the liquid into a solid by making stronger bonds and closer molecules. This is given by E=K*m where K is a coeeficient of freezing in J/kg.

Work is nothing more than a change in energy over a certain time, i.e. W=dE/dt. Both of these factors change, so work must be done. It comes from all of the changing things: pressure, volume, temperature… does ice expand when it freezes? IIRC, I think the answer is yes to about -4 degC but only because water is different from most other liquids. Like I say, it’s been a while since I’ve dealt with this stuff… years even.