I think CO2 retention is probably the most common cause of diving headaches. Since almost all of us want more bottom time, and gas is the final limit of it, it's easy to fall into the trap of manipulating breathing to try to extend one's dive. But CO2 is really bad stuff -- it causes anxiety (and probably underlies a fair number of panic events) and it also causes significant narcosis. Being anxious and stupid at the same time is a particularly nasty combination. This is why, on threads where people are asking how to improve their SAC rates, there are always answers saying, "Don't try to change your breathing to do it!" A regular breathing rhythm with only very short pauses at end inhale and exhale is the goal. Long pauses contribute to CO2 retention (as, paradoxically, does a rapid, shallow breathing pattern).
Most non-divers will experience anxiety and air hunger very quickly if CO2 levels rise, but it has been documented that some divers tolerate elevated CO2 levels without being very symptomatic. Those of us who are like that (and I'm sure I'm one of them) can set themselves up for a fairly bad headache quite easily. I've had NASTY ones after dives into Ginnie Springs, where I worked too hard against the flow.