An important concept we need to know in order to answer that is the idea of hydrophobic materials. These are materials that do not like to mix with water. Gum is a hydrophobic material - it doesn't want to dissolve in water.
Unfortunately, gum is also very sticky. So if it gets stuck in your hair, and you can't use water to get it out, how do you get it out? The answer would be to use another hydrophobic material! And it turns out that one class of materials that is very hydrophobic is fats and oils. And this is precisely what peanut butter is made of!
Additionally, since peanut butter is pretty clumpy, it's easy to work it into the gummed-up hair, and works pretty well at removing most of the mess (although I personally have never tried it, so your results may vary).