As a preface, I know the song you're talking about and those aren't quite the chords. I haven't heard it in at least a decade, but I'm going to use the chords that I believe to be correct in my answer.
There are two general concepts about harmony that are important to understand when looking at progressions that mix chords from the key and chords not from the key:
Chords from outside the key are overwhelmingly common and do not represent a breaking of the rules but an adaptation of them; indeed, when looking at borrowed chords, generally what defines them is their relationship to the "original" key.
Chromatic basslines are also very common and, because they can't occur in a diatonic system by definition*, they necessarily invoke lots of borrowing.
Let's look at the first progression first because it's easier.
BMi | E | G (Gmi) | D (D/C#) |
vi V-of-V IV (iv) I (I/VII)
There's only one standout label here, and it's on the E. In the key of D, E would typically be called V-of-V; it is the chord on the fifth of the key... of the chord on the fifth of the key. This is termed a secondary dominant. Secondary dominants are a relatively advanced concept (particularly if you're not comfortable with what a primary dominant is; if that's the case, I'd investigate that further before looking at secondary dominants). Nonetheless, a brief summary of their purpose is to provide a temporary suggestion of another key: V-of-V suggests V; V-of-IV suggests IV, V-of-vi suggests vi... and so on.
Generally, V-of-V is followed by V, but fairly often it is followed by IV instead. The reasons for this aren't so simple, but basically what it comes down to is the fact that Bmi-E strongly suggests the dorian mode on B (which comes from A major) and then the G quickly pulls you back to the D major system. This is a fairly common chord progression in pop music because it gives you access to a lot of notes while leaving you grounded in familiar territory.
I've also added a Gmi and D/C# in brackets. This is because the chorus almost certainly uses the minor chord on the fourth, at least some of the time, and the bass line that I remember has a pretty fat C# in it. Functionally, these don't change much, but it's worth noting that iv is another very common borrowing and is perhaps the most prominent example of a concept called modal interchange, where chords from parallel scales are used.
Now, the second progression:
C | G/B | Bb | A7
bVII IV/vi bVI V7
(IV-of-IV) (IV)
N.B.: You have this labelled as a bridge, but I'm fairly certain this is a pre-chorus.
This is a chromatically descending bassline. It attempts to get us to the dominant chord in four bars, and so it starts three semitones above the intended root and moves the root down a semitone until it gets to the ending point. At a high level, this is how chromatic basslines work: The chromaticism of the bassline is the anchor. There are few things more common in contemporary music than the chromatic bassline, and to explain all of the possible variations and their differences would require an exceedingly large block of text.
But back to the Spice Girls. The first chord is C; this is another example of modal interchange and it comes from the mixolydian mode. The chord that generally follows the bVII is the IV, and that's what we've got here. The Bb is also an example of modal interchange, but this time we're borrowing from minor; it gives us access to F as a melody note and serves the purpose of moving the bassline one semitone closer to A. The last chord is the dominant chord of our key and serves as an ideal transition back to a tonic chord (in this case B minor).
An important note of distinction here is that at no point in time have we actually modulated to a different key. We've suggested a lot of different scales, but with the exception of E (which, as a secondary dominant, is an example of tonicization) the key we've suggested has always had a tonic of D.
A little disclaimer about my transcription: I didn't actually listen to the song when I came up with these changes and I haven't heard the song for many years. Nevertheless, the only chord that can actually be "wrong" here is G/B, and what you may find that the bass is actually playing a G, not a B. This doesn't affect the overall analysis too much, however, as it simply means that the descending chromatic line is in the melody, not the bass. I will verify one way or another later today.
*Diatonic systems contain one of each letter name; this quickly becomes impossible to maintain with a chromatic bassline.