It is called "предлоги с беглым о". There are also над/надо, под/подо, (о/об)/обо, без/безо, из/изо, от/ото.
Mostly it is used just to make pronunciation easier, for example to avoid too long sequence of consonants. But sometimes it also has a historical and stylistic reasons. Sometimes only one variant is possible, sometimes both.
Formalism of that phenomenon is quite contradictory. You can find several set of rules for each couple of prepositions with a long list of exceptions each. For example "в дверь", but "во двор" - gives no formal rule to differentiate.
As an example here is a rule I found for в/во couple at the popular grammar site "gramota.ru":
Preposition во is used before word forms, beginning with «в, ф + consonant». Also it is normally used before word forms of лев, лёд, лён, лоб, ложь, мох, ров, рожь, рот, before word form мне and word forms многие, многое, множество, множественный, before word form что. Also there are combinations of во with words: благо, весь, глава, двор, дворец, дворянство, зло, мгла, мнение, мрак, сколько, слава, сон, спасение, столько, тьма, христос, цвет, человек, чрево.
But in fact this list is not full. I can remember some other usages of "во" in set phrases and word combinations.