Many people's headaches are related to their consumption of caffeine, most commonly in the form of coffee, tea, soft drinks, chocolate, and medications. Generally the headache is due to a "withdrawal" effect. Caffeine is very similar in structure to another chemical in our body called adenosine. One of adenosine's jobs is to dilate blood vessels in the head. Caffeine blocks this dilation. Your body then has to become more sensitive to adenosine to compensate. The only problem being that when caffeine is withdrawn, your body is overly sensitive to adenosine and blood vessels will dilate, creating a pounding headache. Naturally you reach for another coffee which ultimately results in a dependency or 'addiction' to caffeine. It is due to this blocking of arterial dilation that caffeine is commonly found in headache and migraine medication. It also has the ability to enhance the effects of paracetamol and aspirin.
This information rocks. Not that it helps any, but... hey. It rocks. :)
While I'm at it...
The reaction is (obviously) triggered by the cold ice cream or beverage; coming into contact with the roof of the mouth. It triggers nerves that give the brain the impression of a very cold environment. To heat up the brain again, blood vessels start to swell, which causes the headache-like pain for approximately 30 seconds. The temperature change in the roof of the mouth has to be rather drastic; this is why brain freeze often occurs on warm days. The pain can be relieved by putting the tongue to the roof of the mouth, which logically will heat it up.
And the typical dehydration headache (my daily existence) [[took a lot longer to track down]]:
The body reacts to the open floodgates by borrowing water from other organs, such as the brain. As a result, the brain shrinks. While that may not cause pain by itself, the brain has a covering called the dura that is connected to the skull by pain-sensitive filaments. Deformation of the dura can cause the headaches that come with a hangover.
Actually, that last link has a lot of nifty information around dehydration and such.
((yes, this is what my day has been. went and saw RE2 with a friend--it was fun. I had low expectations and it started off still a bit shaky but was just rollicking silly with a bunch of jumps in it; came home, and have had a headache all day. I managed to do laundry, cook some pasta, have that and some salad I made last night, and read this month's issue of F&SF. And borrowed Harry Potter Year 5 from a neighbor. Meanwhile, I'm still pounding my sore, sore, skull-without-focus on some simple graph theory. :) ))