Most commonly known as a byproduct radioactive decay.
A decay scheme such as Figure "caesium-137 decay scheme" illustrates well how gamma radiation happens as a byproduct of radioactive decay due to the existence of nuclear isomer.
Gamma rays are pretty cool as they give us insight into the energy levels/different configurations of the nucleus.
They have also been used as early sources of high energy particles for particle physics experiments before the development of particle accelerators, serving a similar purpose to cosmic rays in those early days.
But gamma rays they were more convenient in some cases because you could more easily manage them inside a laboratory rather than have to go climb some bloody mountain or a balloon.
The positron for example was first observed on cosmic rays, but better confirmed in gamma ray experiments by Carl David Anderson.