There is probably a build up of minerals on the elements. When the hot water is replaced with cold water the elements heat up really quick and causes the minerals to kind of explode off the element, causing the loud banging noises.
Usually its because the outside temperature of the water heater is so much hotter (in a closet) or so much colder (cold weather climate) than the tank.
When using the hot water in the home, hot water expelling from the tank is immediately replaced with cold water into the tank from above. This mixes in with the boiling hot water thats currently in the bottom of the tank. These sudden temperature changes in the water and tank shifts the tank a little...making noises.