Hydraulic shock (colloquial: water hammer; fluid hammer) is a pressure surge or wave caused when a fluid in motion is forced to stop or change direction suddenly: a momentum change. It is usually observed in a liquid but gases can also be affected.
Water hammer is caused by the surging of pressure which occurs when a valve is suddenly closed. In extreme conditions, this surging will cause the pipes to vibrate or create a pounding noise. Water hammer is most commonly caused by fast-closing valves or pipes that have been sized too small causing high velocity water flow.
An easier way to understand water hammer, picture a train (water) running head on into a wall (fast-closing valve). After the train hits the wall the cars behind it keep moving and slam into the cars in front of them creating the hammer noise.
The only things that can be done to alleviate water hammer would be to install a slower-closing valve or install a water hammer arrestor.
Water hammer arrestors should be installed as close to the source of shock as possible. The arrestor works similar to a shock absorber. It just supplies a place for the water to go when the valve closes to alleviate the hammer.