It's quite simple — it is borrowed from the C mixolydian mode. Which is a pretty awful name, but the concept is very simple.
For start, let's take the C major scale. Here it is, through two octaves:
And now, play all the same notes, just start with a G. You will get a "scale" that is highlighted in red. You can see that it's pretty much a G major scale, only with the 7th tone lowered. This is called the G mixolydian mode. (The name comes from the Ancient Greece. This (and the other mode names) were later taken over by the Roman Catholic Church, which used them for quite some different things, so the name has absolutely no meaning. It's just a millenium long tradition.)
Of course, we can transpose this around easily by noticing that the mixolydian mode is just a major scale with the 7th degree lowered. So a C mixolydian would look like this (look at the first bar):
Of course, you can stack the tones just as if you would with your normal C major scale, and generate some basic triads that go well with the mode. In the C major scale, you would get these triads: C major, D minor, E minor, F major, G major and B diminished. When we flatten the 7th tone, you get the chords shown in the second bar above, namely C major, D minor, E diminished, F major, G minor, B flat major.
So a couple of chords changed, and from among the changes, your B flat major chord appears.
Now of course this doesn't explain why is it such a good idea to use it in a song, and that's always hard to tell, because the only real reason is just "it sounds good". However, I can at least try to give some theoretic reasons:
It's kinda the major scale that everybody hears 1000 times a day, but not quite. It adds a bit of novelty while not being anything totally weird.
To go deeper: in the major scale, the 7th tone is only a semitone from the tonic (the next tone). For instance, in C major, the 7th tone is B. For some reasons, this B can pull quite strongly towards the tonic (C). If you flatten it, it doesn't pull nearly as much, giving a different, maybe more "calm" sound.
Also Michael is very correct in saying that there are other possibilities of explaining the origins of this chord. That's always the case with the music theory; it's never set in stone. It's not math. With just two chords alternating, it's not possible to prefer any one explanation above the others, because the chords have pretty much zero harmonic functions. So this is just one view on it.