When you eat or drink something cold, the cold thing touches the roof of your mouth, which causes the blood vessels to constrict in an attempt to prevent loss of body temperature.
As the coldness fades, the blood vessels dilate, quickly increasing blow flow to the brain. This sudden increase of blood flow in the brain causes intense headache
as you describe. Eat cold things slowly!