This happens when you turn them off quickly.
The water in the pipe has a certain speed when it's streaming. Turning off the faucet suddenly stops this moving mass of water.
It 'collides' with the closed valve. in severe cases this sudden build-up of pressure may even break a (weak) connection.