What happens in water hammer
A flowing column of liquid has momentum. When a valve closes quickly, the liquid immediately upstream is stopped while the column behind it is still pushing on. Kinetic energy turns into pressure. The pressure rise travels as a wave at the speed of sound against the direction of flow, is reflected at the next vessel and oscillates until friction has consumed it.
Downstream of the valve the opposite happens: the liquid keeps moving and the pressure falls. The event is audible as a bang – hence the name.