Brain freeze is the name used to describe the sensation you get when you consume something really cold, really fast. The scientific name for this temporary cold-stimulus headache is
sphenopalatine ganglioneuralgia.
When something extremely cold touches the upper-palate (roof of the mouth), blood vessels in this region dilate to increase blood flow to counter the cold. The homeostatic triggers in your body perceive the cold as a threat to the brain, thinking the brain is in danger from the cold. As the warm blood rushes to your brain, this build-up of blood pressure causes the pain you feel. While brain freezes are not dangerous, they are slightly uncomfortable, so the best way to make it quickly go away is to rub or press your tongue against the roof of your mouth.
Stay safe!