Centering zero frequency for Discrete Fourier Transform
Oh!  What a cool trick!  It works because of the convolution theorem (i.e., multiplication in the spatial/time domain is equivalent to convolution in the frequency domain.)

It's not flipping across the $x$ and $y$ axis, it is rotating the image of the Fourier transform (think of shifting halfway around a cylinder).  The trick here is that alternating -1,1 in the spatial domain is a signal with the highest frequency.  So the Fourier transform of that image is a single point in the frequency domain.  Convolving by a single point is equivalent to shifting (rotating) the image by the offset of the point from the zero frequency.

Here is a test image:
.  It's Fourier transform looks like: 

If you take the Fourier transform of the alternating image (), it results in a single point right at the center of the Fourier transform: .  (Recall we haven't done our rotation yet, so the center of the fourier transform is the high frequencies and the low frequencies are at the corners still.)  But this is the "rotation kernel!"  Convolving with this rotation kernel moves everything down and to the right (but things that fall off the bottom right rotate into the top left.)

Convolving the original image with the rotation kernel (in the image domain) gives you: , while convolving the fourier transform image with the rotation kernel (in the frequency domain) gives you: .

And we can check that multiplying the testimage by the checkerboard in the image domain gives , which has a fourier transform of: .