D&D takes the heaviest amount of "inspiration" they can take from Lord of the Rings as they can without outright plagiarism. Lord of the Rings, meanwhile, was basically inspired by
The ring of Nibelung.
In it, the villain was a dwarf crafted an artifact ring that gave him the power of the gods in exchange for forswearing all positive emotions.
The whole thing was an allegory for the Industrial Revolution, and the basic sentiment was that in exchange for industrial might, humanity was giving up its better instincts, what with all that child labor in the factories and tearing people away from their farms through dubious legal means to work in typhoid-choked cities and all.
Dwarves, living in factory-caves and eating mushrooms were seen as a terrible way to live, whereas elves were seen as living an idyllic lifestyle at peace with nature...
Boy how times change.
Likewise, Lord of the Rings came off with a very Lawful Evil versus Chaotic Good vibe, with the heroes being rangers and simple farming hobbits, while the villains were tyrants who industrially produced their orcish armies.
Yet somehow, "lawful" is now seen as more heavily aligned with "good" now, to the point where "Law" and "Chaos" are basically used as stand-ins in games that want to use Good versus Evil (or just Evil versus slightly less obviously Evil).
Personally, I blame the notion that paladins were somehow paragons of pure good, no matter how relentlessly their brand of "good" has been mocked for the change, although it may well just be the cultural zeitgeist. Somehow individuality and personal freedom became associated with "acting recklessly and antisocially", whereas conformity became a virtue.