What is the phase button for on a microphone preamplifier?

There may be some microphone preamplifiers out there that don't have a phase button, but most do. It might be labelled simply 'phase', or 'phase invert' or 'phase reverse', or something similar.
What it does is turn the electrical signal upside down, so that what was once positive is now negative and vice versa.
Or think of it like this... If you tap on the grille of a microphone (gently) then, according to convention, this should create a positive voltage at the microphone's output. When this travels all the way through the system to the loudspeaker, the diaphragm of the loudspeaker drive unit will move outwards, just as though you had tapped it from behind.
This is the way things normally work and there is little to go wrong, so the phase button should only rarely be used.
Incorrect wiring
The most common reason to press the phase button is that the microphone cable has been incorrectly wired, so that Pin 2 of the microphone's XLR connector, which we call 'hot', goes to Pin 3 of the cable's connector into the preamp, which should be 'cold'.
It is also worth a mention that in years gone by the convention in the USA was that Pin 3 was hot. This changed long ago so it would only apply to vintage equipment.
Why should a cable be wired incorrectly? Anyone who has spent time with a soldering iron will know that out of a bunch of twenty cables there's going be one that's the wrong way round. It normally happens when you wire all the female connectors then start on the males, or vice versa. The first male is the most likely to be wired wrongly as the hot and cold pins are the opposite way around to the female. And don't trust that if you buy your cables rather than make them up yourself then they will all be correct. A cable tester will be your friend.
So the phase button is an easy get-out-of-jail card for an incorrectly wired cable.
Problems in stereo
Oddly enough, for a single mic, this doesn't matter too much because the human ear is not particularly sensitive to whether or not a signal is inverted. But for stereo signals, it matters a lot. The sound of a stereo signal where one channel is inverted is something that doesn't occur in nature and the human ear and brain can't make sense of it. It just sounds horrible.
Multiple mics
There can be another use of the phase button and that is where a number of microphones are used quite close together - a drum set is a good example. It can happen by chance that the overall sound is better with one of the mics - other than the overheads - inverted. You might also consider that the heads of the snare and toms push away from the microphones when struck, but the head of the kick pushes towards the mic. You might want to try inverting the kick (or all of the mics except the kick) to see if this makes any useful difference.
So the phase button - not often used, but very handy when you need it.