From the Discover blog: Why do songs get stuck in our heads?
Having a song, tune, or commercial jingle stuck in one’s head is a phenomenon known as having an earworm. Most people have had an earworm at one time. The experience is harmless and unrelated to both obsessive-compulsive disorder and endomusia, the hearing of music that is not really there. Certain songs—simple, repetitive, or oddly incongruous—have properties that act as mental mosquito bites in that they produce a cognitive “itch.” The condition also arises when people struggle to remember forgotten lyrics or how a song ends. To scratch a cognitive itch, the brain repeats the song, which then traps the hapless victim in a repeated cycle of itching and scratching. Everyone has his or her own list of demon tunes that haunt. Earworms occur more often among women, musicians, and individuals who tend to worry. (OK, so that makes my brain a perfect haven for earworms). Earworms also vary across situations, striking when people are tired or under stress. How can you make an earworm go away? Thinking of something else or actually listening to the song in question are thought to help, but there is presently no research evidence showing what works best. Fortunately, most episodes eventually dissipate on their own.