
A common fix is to install a water hammer arrester.
Water hammer can come from other sources as well. Proper diagnosis is critical. Some water hammer problems can occur when a sprinkler valve opens, versus closes. Trapped air in the piping can cause water hammer. A faulty pressure regulator can be the cause as well. In some rare instances, I have seen water hammer caused by a momentary reverse flow situation when water flow is started either by a hose faucet or irrigation valve opening. In this case a single check valve can remedy the problem when placed at the right location, usually after the supply valve to your house.
Securely fastening loose piping throughout you home can help keep the pipes from banging against the walls too.
Over time, many irrigation zone valves begin to close & open faster than originally designed. This is usually caused by the rubber diaphragms getting stretched out over time. Changing them, or the entire valve, can solve this efficiently. The same thing seems to happen in house pressure regulators (PRV). The diaphragms get weak causing the PRV to cycle or vibrate which can generate various whining sounds as well as causing pipes to bang.
Replacing the PRV will remedy the problem, or in cases where the supply line pressure is low (60psi), one can just remove the PRV.