A nucleus can get more stable by changing the arrangement of protons and neutrons, and giving off a gamma. It’s like rearranging the blocks into a more stable structure.