A pressure change or surge in the line causes water hammer, generally when water is turned on or off. If you are having a problem with water hammer in your line, adding a short branch line with a garden hose may help.
The easiest solution is to lower the water pressure for your entire irrigation system. This doesn't really get rid of all of the water hammer, but it will sometimes reduce it to a level you can live with. The next step is to try a water hammer arrestor. Try putting it on a hose bib close to the point where the irrigation system connects to the house water. If you have a hose bib on the irrigation system mainline, that is an even better spot to place the arrestor.