To elaborate, Dungeons & Dragons has some mechanical elements that don't "mesh" with the quasi-medieval aesthetic. An obvious example would be the implicit ideological autonomy of the alignment system, but even more significantly, a system of magic based on hard values and predictable outcomes (which doesn't at all resemble the chaotic diversity of premodern beliefs concerning magic from around the world).
What influences led Gary Gygax to design and develop the system he did? For bonus points, what were the differences in influence between Dungeons & Dragons, earlier games with similar ideas (if applicable), and relative contemporaries such as Warhammer Fantasy (apart from the obvious matter of scale)?
You've got quite a few questions here which I'll try and address individually and hopefully I won't ramble off-topic too much. There's a lot that went into the creation of Dungeons and Dragons both initially and in subsequent editions so there are a lot of influences to cover.
1 Historical Wargaming Both Gary Gygax and Dave Arneson were avid historical wargamers before they created D&D. They played quite a broad range of historical period but importantly had a fondness for medieval wargaming which has never been the most popular period with the broader community. Gygax attempted to fill in a perceived gap in the available rules for medieval wargaming with his Chain Mail rules. The Chain Mail system had a huge influence on the first edition of Dungeons and Dragons especially as Gygax added fantasy elements and heroes in later revisions. It is perhaps telling that the very first edition of D&D was sub-titled Rules for Fantastic Medieval Wargames Campaigns Playable with Paper and Pencil and Miniature Figures. The simplest history of the game involves Gygax writing Chain Mail, Arneson using the Chain Mail system to run his Blackmoor campaign and then Gygax plus Arneson using the Blackmoor style campaign as a basis for creating the D&D rules set.
2 Fantasy literature D&D borrowed extensively from a wide range of 20th century fantasy literature, some of which was become quite obscure since then. The Lord of the Rings was obviously a huge influence but it certainly wasn't the only one. The system of magic used in D&D, which you noted in your post, was borrowed from Jack Vance's Dying Earth series of books. It was also in part borrowed from Michael Moorcock's Elric books but he had in turn borrowed it from Vance but added some of his own twists too it. If I recall correctly I think the way Scrolls work in D&D is from Elric. Poul Andersons Three Hearts and Three Lions was another big influence and, perhaps most famously, is where D&D borrowed it's style of Troll from. The borrowing from these and other popular fantasy of the time is how D&D got it's strange mash-up type fantasy setting and rules.
3 The Game Diplomacy In addition to being avid historical miniatures gamers Gygax and Arneson played a lot of Diplomacy. They were both active in making their own campaigns for the game by creating alternative boards and settings for it outside of the Pre-WWI default version of the game. The contemporary diplomacy scene is arguably the biggest influence on the roleplaying element of D&D. Gygax and Arneson would play in campaigns where it was expected for players to act in a manner similar to how the country they were playing would act in both play style and in negotiations with other players. This roleplaying plus campaign style game brought a lot of what we consider iconic to D&D to the design of the game.
There are many more influences, like the German Kriegspiel and contemporary fan fiction communities, but they have a less obvious line of influence on D&D. If you're interested in the creation of Dungeons and Dragons I highly recommend Jon Peterson's Playing at the World. It's an excellent book and really thorough. The only caveat I'd place on it is that it is really quite long and dense so there may be more in it than you actually care to know. :)
The magic sysem from Jack Vance's novels, Gygax said that openly, although I don't have that source with me. But here is a Vance novel online, you will find it very familiar (memorized spells forgotten after cast etc.) http://www.e-reading.me/chapter.php/73022/2/Vance_-_The_Dying_Earth.html
Lots of pretty good answers already. The alignement system was strongly influenced by some notions put forth in Fantasy litterature, notably in the Elric of Melnibone series of Michael Moorcock where good and evil are acknowledged, but Law and Chaos play a more significant role. This comes across particularly well in the Melnibonean section of Deities and Demigods.