Just as a gun recoils when a bullet is fired, conservation of momentum requires a nucleus (such as in a gas) to recoil during emission or absorption of a gamma ray.
Nuclei in a solid crystal, however, are not free to recoil because they are bound in place in the crystal lattice.