|Art by Zeke Nelsons, used with permission
In the early editions of D&D, the idea of buying and selling magic items was absurd. Magic items were wonderful things you discovered in the dungeon that either made your Fighter more powerful or did cool, odd things.
2nd Edition let spellcasters craft magic items, but it didn't let you buy them. Crafting magic items wasn't a formulaic system like Pathfinder or even the fairly simple "spend some gold and cast a ritual" method of 4e. You had to go on quests, designed by the DM, to get the required components to make them.
Random magic item tables made their discovery a surprise to everyone at the table, and early edition D&D fighters (original, 1e, BECMI) did not specialize in any particular weapon or weapon type like they came to do in the post-millennial editions. (With the exception of BECMI weapon mastery, but you didn't choose a weapon to master until after you had found a magic weapon, typically.)
2nd Edition came out in 1989, and it was the last edition before we started seeing magic item shops. What happened between 1989 and 2000, when 3rd edition came out and put price tags on every magic item?
Magic Items in Shops in JRPGs
To find the answer, we need to look at the history of another, parallel, emergence of magic item shops: JRPGs (Japanese RPG video games).
JRPGs like Final Fantasy and Dragon Warrior have shops where you could buy progressively better weapons and armor. In the mid-80s, the weapons and armor you could buy from the shops in these games were not magical - they would start off shoddy, like "wooden" or "copper" or "iron" and then advance to special materials like "elven" or "silver" or "golden" or "mithral." The magic weapons and armor like a fire sword were only found in treasure chests in dungeons.
These early JRPGs were inspired by D&D, which was coming over from the US. Naturally, mundane items could be bought in town, and magic items could be found in dungeons. It made sense.
But something happened in the "black box" that is Japan. Since I can't read Japanese, I can't go read old Japanese RPGs from the early 90s, but between Final Fantasy / Dragon Warrior and Final Fantasy II (US numbering) / Dragon Warrior IV, the idea of selling magic items in shops became acceptable in Japanese fantasy RPGs. It's possible the evolution happened within the video games themselves, or perhaps a Japanese tabletop RPG introduced the idea first. Regardless, after the release of 2nd edition D&D, we experienced a full decade of video games based on D&D that incorporated buying and selling magic items into their idiom.
The 1990s-era JRPGs evolved more and more magic items for sale, starting with a few, and evolving rapidly. By Final Fantasy IX (2000, same year as D&D 3rd edition's release), you could go to a store in a town and buy swords with ice and fire spirits bound to them, angels inside them, and swords inscribed with magic runes. Not to mention any number of magic rods, bangles, flutes, etc.
From "golden swords" to "diamond swords," the items for sale got more and more fantastical from the mid-80s through the mid-90s. Eventually there were magic items in shops, and then there were entire magic item shops.
Magic Item Shops in Tabletop RPGs
The idea of magic item shops is so unique to video games that it only ever crops up in fantasy fiction as a tropey, lampshaded in-joke.
Magic item shops are not part of most official D&D settings -- even the post-3e settings. In 2nd edition, in the Forgotten Realms, there was one magic shop -- in Hilsfar (thanks to POCGamer for pointing this out!). The magic-flush Eberron setting of 3rd edition, for another, doesn't have magic item shops so much as Dragonmarked Houses (essentially dungeonpunk megacorporations) that produce and sell them mostly to high-class clientele (e.g. other Dragonmarked Houses, nobles, etc.). A growing middle class in cities like Sharn can get hold of minor trinkets - healing potions, feather fall tokens, flying skiffs, and (for the richest) elemental-powered ships. But these are arranged through appointment with an artificer of the appropriate dragonmarked house. There aren't flying skiff dealerships you can walk into with a down payment and walk out of with a slick, new model-year air-skiff. In other words, the idea of a store you can walk into and buy magic items off the rack doesn't even exist in the most magic-rich D&D campaign setting.
Magic item shops are in Pathfinder (mentioned in both the Settlement rules and Magic Item rules), and though they aren't typically found in Pathfinder's Golarion campaign setting, settlements often have magic items for sale, somehow. It seems that the idea is so odious that it gets hand-waved.
In 4th Edition D&D, where magic item buying and selling peaked, you took a ritual to make magic items, so the party Wizard was typically the party's magic item shop. You could also take a ritual to break magic items down into residuum, which was just "store credit" for the party wizard's ritual. In a way, this harks back to 2nd edition, where spellcasters could make magic items, only with gold piece price tags and without the cool quests.
Between the late 90s and the 'teens, D&D and JRPGs diverged considerably. Final Fantasy now has motorcycles and gun-blades and rock 'n roll music. JRPGs have largely left D&D behind in the realm of pseudo-European pseudo-medieval fantasy while they've gone off in different creative directions.
5th edition takes us back to the style of 2nd edition. Gone is the "video gamey" nature of 3rd and 4th edition (and Pathfinder). Though there are optional rules for magic item price tags, I don't think most DMs use them.
Is D&D its own genre?
It's clear that magic item shops aren't core to D&D's idiom, which is evidence of the idea that D&D is its own fantasy sub-genre. Briefly, JRPGs tried to emulate D&D's style, but they diverged. D&D spent two editions and a decade and a half following JRPGs before breaking off and returning to its roots.
Personally, I've always felt D&D carries its own subgenre of fantasy. Trying to run other kinds of fantasy in D&D can be difficult - the odd monsters, the way magic works, the idea of levels, party dynamics, the commonality of magic items (even in relatively stingy 5e)...
All that goes to support the idea that D&D is not just an RPG to tell sword and sorcery fantasy stories in, but specific kinds of sword and sorcery stories where there are lots of bizarre monsters to fight in remote, isolated dungeon-like locations; where there is treasure in the form of magic weapons, armor, and wondrous items; where there are spell scrolls and potions; where there are Rogues and Paladins and Clerics. It grew out of tabletop wargames, and the roleplaying part slowly grew on top of the game part, giving us the feel of players moving game pieces, trying to accrue more powerful items and abilities to take on still stronger and more bizarre monsters and get still more powerful and wondrous items and abilities. Even if you don't play D&D that way, it's baked into D&D's system and idiom. No matter how you try to play D&D, you can't help fighting bizarre monsters and accruing powers and magic items that allow you to fight tougher and weirder monsters that reward you with more and better powers and more and better magic items.
Personally, I revel in it when I run or play D&D. To me, Out of the Abyss -- the most "D&D" of the published 5e modules to date -- is the ultimate expression of the subgenre. It's especially egoistic. The first half of the module is all about gaining power and experience (in order to escape the underdark). It's full of dungeons and bizarre monsters. You find odd items. Magic is everywhere. It's weird often to the point of being playfully silly. It's fantastic.