I'm not talking about legitimacy in the abstract, or about our perception of legitimacy, but of domestic perceptions of legitimacy.

In countries where colonial occupiers or hated dictators have to be expelled by force, those who did the expelling typically earned a significant perception of legitimacy simply by expelling the colonial power or hated dictator. In many cases those governments did perfectly awful things: taking power through armed struggle often means that the most ruthless and aggressive people in the movement end up running it. The awfulness of what those governments did when they gained power does not change the reality that success against an occupying colonial power or hated dictator does typically - at least initially - earn a movement a significant degree of perceived legitimacy. Similarly, those who supported the colonial power typically earn a degree of illegitimacy, even if they are in many ways more able to run the country.

One of our consistent problems in the Cold War in the developing world was identifying conflicts as "communist vs non-communist" while local populaces identified the same conflict as "colonial power vs national liberation movement" or "detested dictator vs those who fight the dictator" or "foreign intruder vs local resistance", with very little emphasis on or understanding of whether anyone was a communist or not. While for us the identity of those who were "communist" was of surpassing importance, it often meant very little to those who saw the insurgent as the enemy of their enemy.