I wonder are you living your n relatively old house. Maybe you still have the old lead pipes installed. And maybe you still have the old accompanying mains welded valve to switch off/on the water.
Maybe you hear similar noises when you use your own taps around the house. Actually when you turn the tap on or off.
I’ve heard of cases where that old mains valve required replacing in order to quell such a banging noise. In those cases, it’s how the valve ages and wears. And then how the valve moves or vibrates as the mains water pressure rises and drops.
Those rises and falls in pressure typically occur either when the local waterworks turns the pressure up and down to cater for peak and off peak times of the day, e.g. breakfast time, dinner time, or as the water is being used in the house.