What has been D&D's strength from the beginning has been how it could be used to delve into so many different genres. If you look at Judges Guild and Greyhawk, for example, you see post-apocalyptic tales, medieval warfare, sci-fi-fantasy blends, the game of thrones. It's silly, it's gritty, it's gonzo.
Even today, you see people taking 5e in wildly differing directions. I forget who did it, but someone ran a Downton Abbey campaign using the D&D Next rules, before it had even come out.
I will say that D&D, as it's own genre, has a love of codification that was probably most felt in the late 70s/80s with fantasy literature, but even today, you can see with stuff like Brandon Sanderson's works.
For me, D&D is "scifi" (including fantasy and other speculative fiction).
D&D is near-future. Magic = supertech. All contemporary challenges are present in D&D, whether gender equality or environmental concerns or the blurry line between humanity and magics-and-or-technologies.
If the setting is in year 2040, I want the supertech cop to be the Paladin class swearing the oath of a police officer. The popculture supertech holistic medicine guru to be the Bard class. And so on.
If the setting is in year 1040, I want Dancing Lights cantrips and similar magic illuminating city streets, and people aware of governmental ethics.
In scifi, in practice, the palpable difference between years 2040 and 1040 is the size of cities. For 1040, the DM can put every go-to location on a single page map. The entire city within the walls might be only 10 city blocks apart. For 2040, the city space is vast and sprawling, with patchworks of loosely defined neighborhoods, where the go-to places scatter randomly with no obvious relationship to each other, difficult to know and navigate, and challenging for the players to know what to do next.
Also, for 1040, divination magic can monitor public places. But in 2040, the surveillance technology makes "divination magic" impossible to ignore. Everything that players do has consequences.
Depends on the edition of the game, and whether it has a core assumed setting. I know with 5E, WotC has tried to keep the genre labels for the actual settings/worlds, and not the core rules system. but despite them saying the default setting for 5E is the Multiverse, there is still enough Forgotten Realms baked into the core books to counter that. So it is vaguely late Medieval to early Renaissance European fantasy with a generic High-Magic Fantasy genre.
The same genre as L. Frank Baum and George Lucas' fantasies.
That is to say, there's science in the fantasy and there's fantasy in the sci-fi and it's definitely American in character but influenced by the classical romances, fantasies, myths, and folklore of around the world (but especially that of Europe).
D&D's genre isn't medieval so much as it's "renfaire". Or Society for Creative Anachronism. It's an American concept of the Middle Ages deeply rooted in what the popular consensus of the Middle Ages was in the 1970s and 80s.
Mixed with a heavy dose of the American concept of a frontier from western narratives and a huge dose of pulp fantasy.