A distinction between an "exonym" (name outsiders use) vs. "endonym" (names insiders use) can happen for a number of reasons, but the primary cause is probably lack of knowledge about the other group's language.
One factor is prejudice, particularly if two groups don't know each other's language. The Greek term "Barbarian" is such an example, implying that a group can't speak properly.
However, a group may use multiple names. For instance the group of Old English speakers (the Angles, Saxons and Jutes) became "English" as an endonym, but Welsh preserves the term "Saeson."
Another way exonyms happen is misinformation through a third party. For instance the name "Japan" is said to come via Chinese. So English is attempting to adapt a Chinese pronunciation of a Japanese pronunciation - it can get confusing. A number of exonymns may actually be coming in this route. Imagine that a group of travelers working through a large set of new lands. As they come to each new group, they may ask about neighboring groups and may receive the wrong name.
Biased geography can also result in an exonym. An example is the term "Indian" for pre-European populations of the Americas. This dates back to a time when Europeana may have thought they were in India, and the name has unfortunately stuck. Similarly the Lenape are called the Delaware because they once lived near the Delaware river.
Mispronunciation is yet another factor. The Cherokee are actually Tsalagi, and it is plausible that "Cherokee" is just a bad Anglicisization.
So as you can see, there are lots of ways to misunderstand a group's name.
Elizabeth J Pyatt
Sometimes languages are known by the name their neighbors and quite possibly rivals give them. The Ekpari people, for example, of Nigeria's Cross River State are listed officially in Nigeria as Yache, a name the neighboring and more powerful Yala people gave them. The Tiv people of Benue State are called Munshi but many surrounding groups, a term they find insulting. It's rather like the British calling the French "frogs" or us calling the Germans "Krauts." Which name gets official use is, of course, a matter of political, military, and economic power.
Herbert Frederic Stahlke
Just to add a further example to what Profs. Pyatt and Stahlke have said, I would mention the Iowa city called 'Des Moines'. There's a Trappist monastery near the city, which many people assume is the origin of the name -- but in fact, the city (and its name) predate the monastery by about 30 years. The name actually comes from a Native-American group living on the opposite (east) side of the Mississippi River, who when asked by European explorers about the people in that region answered with an expression which the Europeans heard as 'Des Moines' but which in the local language actually means 'shit-faces'; the implication being, 'You don't want to do business with those people; do business just with us instead!'
Japan ... (more)