The movement of the diffraction spikes is similar to the phase detection autofocus that's been used in SLR cameras for decades. Before the days of autofocus, many SLR cameras had a split-image viewfinder that used the same principle as well1.
To keep things simple, let's consider a mask with just two slits out at the very edge of the aperture.

Now let's consider what that does as we're focusing. I'm going to draw things in terms of a refractor, but using a reflector doesn't really change things. So, here's a simplified (and drastically not to scale) diagram of light coming from a star, going through the two slits above, and coming into focus on a plane behind the lens:

So, we have a star on the left, two rays of light leaving the star and traveling to the two slits, going through the slits, being refracted by the lens, and coming into focus on the plane. The image is in focus when the two rays of light come back together precisely at the surface of that plane. So what we see when we look at this should be basically a single line. We really have two diffraction spikes, one from each slit, but since we've brought it into perfect focus, they'll line up with each other perfectly. So, in simplified (and hand drawn) form, what we see looking at this, is a picture like this:

Two diffraction spikes, but they align perfectly with each other. I've drawn a boundary between the two, but in real viewing, there won't be an obvious boundary at the edge of each diffraction spike--we'll just see basically a single line.
So let's consider what happens when we move that plane, so the image is out of focus. The rays of light continue to be refracted to exactly the same degree, so we end up with something like this:

In this case, we can see that the two aren't hitting the focus plane at the same point, so what we'll see will be two mis-aligned diffraction spikes:

That explains how (some of) the spikes appear to move as we focus. That leaves another obvious question: how do we get the other spikes that don't move as we focus? That's actually pretty simple. If you look back at the first picture above, there's a crucial fact to note. The slits are (at least approximately) tangent to the aperture.
To form the X-shaped diffraction spikes, the Bahtinov mask uses slits that are radial instead. Technically, these do still move (a little) but it involves the diffraction spike moving along its length instead of sideways, so it's much less visible even at best. There's also little or nothing at the end of each diffraction spike, so you don't have much to compare against to see the movement.
Beyond that, it's all "user interface" enhancements to make it easier to use: More slits, carefully aligned with each other, project diffraction spikes on top of each other, so you get what looks like a single diffraction spike that's a lot brighter. The X-shape guides you eye toward the place you should be looking to see whether the spikes are properly aligned, and so on.
Now don't get me wrong: those are important, and definitely part of the genius of the design--but the basic principle of how/why the spikes appear to move relative to each other remains the same (and why some move but others don't appear to).
1. Note that many rangefinder cameras also used split-image focusing, but it worked rather differently--what I'm talking about here is strictly the version used with SLRs. An SLR with a split-image viewfinder used the same principle as shown here. The difference is that instead of using an aperture with slits, it used a pair of prisms at the center of the viewfinder to collect light from near the edges of the lens. But it still used the basic idea of collecting light from two opposite edges of the aperture, and showing them next to each other, and your focusing by aligning the pictures showing from each. It didn't use diffraction spikes, because in normal photography you typically have objects in the picture with obvious lines in them. Diffraction spikes just let us take subject matter that's mostly just dots, and creating lines from them.