@oristarA,
I don't know what the scientific explanation is (although I'm sure you can find out pretty quickly through a Google search) but serious infections result in a "throbbing" sensation in the infected area, which is to say a continuous series of pain waves.
Although headaches are infrequently the result of infections, they can produce a similar throbbing effect, particularly if they are part of a hangover.
The scientific explanation may be different as the sensation is not identical, but it's close enough to justify the metaphor used.