Absolutely great question. i’ve always wondered this myself, until I did a bit of research on it there.
So, though it hasn’t been proven, it’s probably down to being good neighbours with other humans! As we evolved from primates into the human race and spread all around the world, language evolved as a way of communicating. So when we were separated from each other by seas and mountains, different languages came about. But what about the many tribes of people that lived in the same place, like on the same continent? How could we tell who was part of our tribe and who was from a neighbouring tribe, if we all spoke the same language? That’s where we think accents came in, as a good way of being able to tell where someone was from if they lived near you but were not related to you. Our brains are already good at being suspicious of things that are different because it could be dangerous…. After all, evolution is all about preserving your genes and those of your relatives. So, accents were a good way of making sure you were helping people closely related to you!
Think of all the accents in Ireland. Even though we’re part of a single country speaking the one language, our nation is based on tribes of people who originally didn’t really get on… And we still basically have tribes; our counties! I definitely know a Cork accent from a Mayo accent or Dublin accent!