First, an analogous... analogy. There are signs on most bridges warning of ice. The reason for this is that, while regular roadways are protected from fast changes of temperature because these quick changes don't penetrate the ground very quickly, on a bridge, both the top and the bottom are exposed to the air, so they will be colder and freeze faster than roads insulated by the ground.
The mouth is similar with regards to "brain freeze." Obviously, the brain doesn't freeze. The picture above shows a lot of internal areas of the head and neck. Between the oral and nasal cavities is the hard palate. When you're eating cold foods or liquids, the first part of each swallow includes the tongue pushing the bolus (food or liquid that's chewed and ready to swallow) against the hard palate and back towards the back of the throat. Since the hard palate has cold items against its bottom side, and air passing through the nose on the top, it is not well protected against temperature changes.
So it gets cold. And this is what a "brain freeze" really is. I don't know of any advice to get rid of it. I close my mouth and keep my tongue against the hard palate, which should provide some insulation and help to normalize its temperature faster.
To prevent brain freeze I have two suggestions. 1) Don't eat or drink cold things. and 2) If you do eat cold things, keep them moving around in your mouth until they are warm before swallowing them.