I believe caffeine is both a treatment for, and a cause of headaches. [1] Excedrin for instance is a migraine treatment which includes Tylenol and caffeine.
Reason it’s a treatment is helping absorption typically, but also, a lot of people’s headaches are from withdrawal so it helps in the way drinking a beer helps a hangover.