D&D has basically been developed as a set of mechanical rules that has some vaguely-implied generic setting - for example, there are clerics and druids, that both do semi-similar divine magic, but they're distinct and different. Devils, demons and elementals all exist, and can be summoned from other planes, there's an astral plane that some spells interact with, etc. etc. It's pretty much always been like that - the earliest books had rules and mechanics, which would imply some setting stuff (e.g. "dragons exist and are terrifyingly powerful"), that certain spells are around, and things developed from there. After a while, extra things got developed, like the elemental planes, the alignment planes, astral and ethereal planes etc., which have since become a soft "generic setting" that's a vaguely-default setup for D&D gaming (and can have mechanical effects if changed - if your world has no ethereal plane, that means some effects won't work the same way!) The rules came first, then people made up a setting after the fact, rather than the setting, and then rules that precisely reflect the setting (which is why there can be odd messes between "how the world is described as working" and "what the rules actually say" sometimes!) You can get a collection of a load of the old books published as part of the 50th anniversary: https://www.amazon.com/Dungeons-Dragons-Making-Original-1970-1977/dp/0786969857 It's interesting as a historical artefact, but is very clunky as an actual ruleset, and the original design involved a lot of things that modern play doesn't do (it's a lot more directly adversarial between the GM and the players, as well as lots of random things). A lot of other older books you can get as PDFs if you want them - hunting down physical copies will be a lot harder though, as they're 30, 40, 50 years old! Lore-wise, it was largely AD&D-era when most of the "big" settings got established - Forgotten Realms (which got multiple sub-systems - Al Qadim is pseudo-Arabia, there was pseudo-South-America, Pseudo-China, and a LOT of supplements covering everything), Planescape (lots of details about the planes, how they connect and what happens there), Ravenloft (hammer-horror-esque, lots of mini pocket-realms with their own bosses) and so on. These are mostly fairly easy to get as PDFs, if you want them, and often have lots of maps (originally posters in box sets)
