Don't think of magnets and electrons, just think simpler.
Let's play some ice hockey. To simplify this game, it's just one player, who I'll call "us", with a puck, in a really big rink. There isn't even a proper enemy player, just a big wall in the middle of the rink, trying to stop us. We can only go through a "gap" in the wall. Let's say the puck is moving forward, straight from our goal to the target goal, and we're travelling with it.
We tap it once, say to the left, so that it can go with us towards the gap in the wall.
Then when it's in line with the gap, we tap it once to the right, so that it goes straight. We thereby pass through the opening in the wall with the puck.
Now we tap it again to the right, so that it comes to the center line again. When it's in line with the center line, we tap it again to the left to stop it. That's what this last magnet is doing, it's giving this last tap to stop the things.
The pattern of taps is L, R, R, L. If we are really precise with our taps, or the "wall" is not very big, we can condense the two R taps into one bigger tap 2R, which does both of them. Instead of going straight through the gap it now goes diagonally through the gap, possibly turning right as it goes through, depending on when we tap it.
Let's say the Y direction measures progress towards the other net, with the X direction perpendicular. The puck's horizontal momentum $p_y$ is some constant because there is no friction. Its horizontal momentum $p_x$ however changes as we tap it: it starts at $0$, then goes to $p_1$, then goes to some $-p_2$, then goes to $0$ again. This requires at least three impulses: one of magnitude $p_1$ to take it from $0$ to $p_1$, one of magnitude $-p_1 - p_2$, to take it from $p_1$ to $-p_2$, and one of magnitude $+p_2$, to take it back to $0$.
The evolution for a particle with a well defined spin along the $z$-axis is :
$$\begin{array}c
I && III && V \\
|\phi_I\rangle\otimes|+\rangle_z & \longrightarrow & |\psi_\uparrow\rangle\otimes |+\rangle_z & \longrightarrow & |\psi_V\rangle\otimes|+\rangle_z \\
|\phi_I\rangle\otimes|-\rangle_z & \longrightarrow & |\psi_\downarrow\rangle\otimes |-\rangle_z & \longrightarrow & |\psi_V\rangle\otimes|-\rangle_z \\
\end{array}$$
where $|\phi_I\rangle, |\phi_V\rangle$ are wave-packets localized in region I and V respectively, and $|\psi_\uparrow\rangle$, $|\psi_\downarrow\rangle$ are localized in region III on the up and down path respectively.
In the usual Stern-Gerlach experiment, the position of the particle in region III is measured, which allows to tell $|\psi_\uparrow\rangle$ from $|\psi_\downarrow\rangle$ and in turns gives us the spin of the particle.
Now, consider any particle at the start of the experiment. Its state is :
$$|\Psi_I\rangle = |\phi_I\rangle \otimes |u\rangle$$
where $|u\rangle =\alpha |+\rangle_z + \beta|-\rangle_z$ with $|\alpha|^2 +|\beta|^2= 1$. By linearity, it evolves as :
$$\begin{array}c
I && III && V \\
|\phi_I\rangle \otimes |u\rangle & \longrightarrow & \alpha |\psi_\uparrow\rangle\otimes |+\rangle_z + \beta |\psi_\downarrow\rangle\otimes |-\rangle_z & \longrightarrow &|\psi_V\rangle\otimes |u\rangle
\end{array}$$
ie, the spin of the particle is unchanged. Looking only at $III\rightarrow V$, the superposition interferes just in the right way to give the initial spin state.
(In the book, they choose $\alpha = \beta = 1/\sqrt 2$, ie $|u\rangle = |+\rangle_x$, but this works for any initial spin state)
Best Answer
Excellent question! To understand the reason for this, neither expectation of $S_x$ or $S_y$ going to zero is sufficient. One could setup equations from relevant commutation relations and get the probabilities but that’s equivalent to doing the matrix algebra. Let us see if symmetry helps simplifying things.
The fact that $\langle{S_x}\rangle=0$ enforces the weightage between the plus and minus states along x to be equal. This means they are of the general (real) form as follows: $$|{+,z}\rangle=\alpha~ |{+,x}\rangle ~+~\sqrt{1-2\alpha^2} ~|{0,x}\rangle ~+~\alpha ~ |{-,x}\rangle \\ |{-,z}\rangle=\beta~ |{+,x}\rangle ~+~\sqrt{1-2\beta^2} ~|{0,x}\rangle ~+~\beta~ |{-,x}\rangle $$
But the symmetry of the problem dictates that if you flip the system by $180^\text o$, you should get the same probabilities. In other words, keeping things real, $$\alpha=\pm \beta$$ Finally, using the fact that the plus and the minus states along z are orthogonal, we get, $$-2\alpha^2 + 1-2\alpha^2=0\\ \Rightarrow \alpha^2=\frac{1}{4} $$
Where we have chosen $\alpha=-\beta$ as plus would imply both the states are equal.
As you can see this is, like many things in physics, ultimately an outcome of symmetry.