The opening harmonic progression of the B minor mass:
Bm moves to a C# half-diminished 7th — a ii7 chord, nothing unusual yet. To put it in root position is a bit unconventional for the style, but the stepwise motion in the bass is worth it. A common predominant chord.
Instead of the expected dominant, however, Bach throws in a V7-iv chord, a B7. This does move to Em as expected, but to shift from a ii7 to a secondary dominant isn't something you see very often, especially not a V7-iv.
The rest of the opening is pretty conventional, with a V7, i, VI, very brief ii7, and finally resolving to a V. I'm mainly asking about the ii7 to V7-iv, which seems like it should sound very abrupt, yet it does not. Why does this progression make sense to our ears?