This problem occurs due to the fact that water cannot be squashed. Ok what happens is that the water is flowing happily and then the tap is turned off fast - this is like running into a brick wall while gently turning off the tap is using the brakes!
When the pipe goes round a bend, which is not well enough supported, then the pipe can vibrate backwards and forwards to make the noise. This is produced by the water in the pipe vibrating and it does so due to the fact that hot water readily produces water vapour and the water/vapour interface permits an oscillation to start. A sudden turn off will start a violent oscillation but a slow turn off allows the potential oscillation to subside. The water oscillation is transferred to the pipe and hence the mechanical noise!
So look for a bend in the pipe and try to support it better.
best wishes Nyge, March 2011