I found this article to be pretty interesting.

Modern nationalism valorises a people’s deep, primordial relationship with land. It also depends on enemies, outsiders and foreigners to help unite the members of the nation…

For much of Western history, however, claiming foreign ancestry was the key to political legitimacy. From the Roman Empire to the Renaissance, noble families across Europe insisted that they were not related to the populations they ruled. They traced their ancestry back to illustrious foreign powers, including figures of myth and legend. Among the most popular were the protagonists of the Trojan War…

…from the long view of European history, nationalist myths about indigenous peoples are a recent invention, a response to elites’ emphasis on their foreign origins.

The article doesn’t mention it, but I think another good example of this would probably be the Jewish origin myth of the Exodus. The archaeological consensus is that it never happened, there was never any mass migration from Egypt to Palestine, nor was there any overthrow & expulsion of Canaanites. What most likely happened is that at some point, the Canaanite society experienced a political collapse, the local population started self-identifying differently, and a cohort of self-identified “Israelites” successfully took up the vacuum of power and formed a government. Then they invented an origin myth about how they were actually from the exotic land of the Nile, even though they were really just the same ethnicity as the Canaanite rulers of a generation or two earlier.