Upon being informed that villain is related to a Latin word meaning "inhabitant of a villa," one might conjure up images of a mustache-twirling villain conniving evilly at his sprawling villa. The history of the word, though, is far more complicated than that.
The story does start with that Latin word. Actually, it's a Medieval Latin word: villanus. The fact that it's Medieval Latin matters because although the word villa in classical Latin referred to a large country dwelling, by the time of Late Latin—the 3rd to 6th centuries—the word could also refer more generally to any aggregation of rural dwellings, making it nearly equivalent in meaning to village. Medieval Latin came after Late Latin (Medieval Latin was in use from the 7th through the 15th centuries), making villanus, with its "inhabitant of a villa" meaning, basically a synonym of villager—which doesn't exactly evoke that evilly conniving villa-abiding villain.
The landed aristocracy (those at home in villas in the classical Latin sense of the word) dominating medieval society in the days of Middle English had all the power, politically and linguistically, and under their use of the word, the Middle English descendant of villanus meaning "villager" (a word styled as vilain or vilein) developed the meaning "a person of uncouth mind and manners." As the common equating of manners with morals gained in strength and currency, the connotations worsened, so that the modern word villain is no unpolished villager, but is instead (among other things) a deliberate scoundrel or criminal.
A glimmer of this history is visible in the dictionary entry for villain: the earliest meaning of the word is "villein," a word that refers (in part) to a free common villager or village peasant lower in rank than a thane. Research on whether such villeins twirled their mustaches has so far proved inconclusive.