D&D got it's start in the 70s, and apocalyptic and post-apocalyptic fiction was definitely out there. 70s sci-fi (50s-70s, really), until Star Wars changed the game, just loved dystopias, nuclear wars, environmental catastrophes, and, when the production wasn't too expensive, their aftermaths. Damnation Alley, Deathsport, Logan's Run, Planet of the Apes, A Boy & His Dog, and many others... back to On the Beach, I suppose. The pulp fiction that in part inspired D&D, like Lovecraft, also had an affection for lost civilizations and the like.
And, it's not uncommon, in genre, for magic to have been greatest some time in the past. (Tolkien's Palantiers, et al, above). Myth/legend also tends to credit the past with mystical secrets and golden ages.
In early D&D, that vein is very evident both in the emblematic dungeon-crawling (exploring ancient ruins expecting to find /better/ stuff than you could get at the surface), and in the most powerful items being Artifacts & Relics. D&D doesn't lack for good candidates for Lovecraftian remnant elder races, either: Mind Flayers, Kuo-toa, Drow, Spellweavers, even elves if you're feelling a little suspicious of them.
One difference between the typical sci-fi Mad Max post-apocalyptic setting and the presence of the theme in D&D is that D&D tended to have perfectly functional societies built over the ruins - the apocalypse having happened long ago.