There are 2 reasons we get a song stuck in our head, for either creation or release.
Music is not only connected to the energy system inside of us, and the whole of the universe. It is present during times in our emotional development.
Because of that, there is often a soundtrack accompanying our deepest emotional wounds. This is where our energy got stuck due to not having an avenue of safety and comfort to be released in.
Listen to the song stuck in your head. Hold compassionate and kind space for whatever emotion(s) arises, for as long as you need to. This is one of the many ways we gain emotional freedom.