Early human settlements created different languages in different locations. Although we can only guess about this variety, we can look at countries like Papua New Guinea, with over 850 languages (14% of all the languages of the planet) for 6 million inhabitants, or the Arnhem Land (in Australia), which used to have over 250 languages for a population of about 20,000 people (nowadays there are only a couple of dozen languages still strong), and a similar picture can be found in the Caucasus, many parts of Africa, Indonesia (over 700), Latin America (over 250 in Mexico and 80 in Colombia), Brazil (with over 180), etc. Even in USA there are over 160 native languages still spoken by minorities.
Languages becomes official over large areas because a group of people become the dominant one, and the language is imposed by force, or it is required to do business and trade with the group in power, or the culture simply overwhelm the others. Our ability to be in touch with the rest of the world is also contributing to displace languages of people without the money and the resources to reach enough audience.
By the 10th century, in Spain there were many different dialects and languages: Catalan, Mozarabic dialects, Galician-Portuguese, Astur-Leonese dialects, Navarro-Aragonese, Castilian and Basque, which is totally unrelated to the rest (or Latin). Galician-Portuguese split into the modern Portuguese and Galician (spoken in Spain). The Castilian dialect was only spoken in a small region called the kingdom of Castilla, in the north of Spain. This kingdom began to expand its territories, until it became the largest one, and eventually, it was chosen as the official language, although it was never influential enough to completely displace all other dialects and languages, which are still used nowadays. If we all spoke the same, the question would be: how did Castilian manage to wipe out all other dialects and languages?