Moving water carries momentum. Snap a valve shut — as washing machine solenoids and quarter-turn taps do — and that momentum converts into a pressure spike that hammers through the pipework, rattling loose pipes against the frame.
Beyond the noise, repeated hammer fatigues joints and fittings. Fixes range from securing loose pipes and slowing valve closure to installing hammer arrestors near the offending appliance.