Your brain is basically that one friend who can't sit still for five seconds without humming the chorus to some forgotten cereal commercial from 1997. Scientists call it a "cognitive itch." Your brain calls it survival. Everyone else calls it annoying.
Here's what's actually happening. Your brain gets bored, starts looping familiar patterns, and suddenly you're standing in the shower belting out a jingle for a product that no longer exists. The neural loops kick in, your brain locks onto the earworm like a dog with a sock, and no amount of willpower can shake it loose.
Some researchers say the best cure is to listen to the full song and let your brain complete the loop. Others say chewing gum works. Both of those people clearly haven't tried a proper cup of black coffee in the morning.