So -- why is fantasy clearly the most popular genre in the TTRPG space? Even discounting D&D, most RPGs are some flavor of fantasy, and many of those at least vaguely "medieval fantasy."
Why do you personally think that fantasy is so over represented in RPGs?
I think, to answer the why, we cannot discount D&D. It (D&D, not TSR) was the first, the first big hit, and has arguably* retained hegemon status throughout the entire era of TTRPGs as commercial products. This should be acknowledged, so we can then discuss all the other reasons, but it's also useful to realize that part of the reason why D&D did catch on could be fantasy aspects that contribute to making an engaging TTRPG.
*yes, we all know those technicalities one might want to bring up.
Firstly, although combat need not be as dominant as D&D (a spin-off of a wargame) made it for a long time, decisive physical action as a major avenue of success-determination is a good fit. Romance* simulation is something a lot of people in gaming wouldn't have been comfortable with, and mysteries have issues with GMs building fair** mysteries with clues that could (but wouldn't automatically) reasonably lead the investigators to the right outcome. So activities that fall under the general 'action movie' genre are pretty natural choices.
*of the rom-com variety, not as C. S. Lewis might write about
**teenage me had a hard enough time building fair traps.
As to why medieval fantasy as opposed to westerns, cliffhangers, modern fantasy, or sci-fi, I think there are a number of factors (none absolute):
- Fantasy allows magical solutions that work as the game needs them to. Similarly tricks and traps that IRL would be nonsensical (but interesting) are usually given a pass in fantasy scenarios.
- Fantasy removes certain elements of current or future scenarios which might eliminate entire categories of challenge.
- Fantasy allows a team of characters with differing traits to work together and share the spotlight.
- Fantasy creates the ready situation of many varieties of opposition (many of which being bestial, unintelligent, or pure evil, minimizing moral quandaries) to appear.
- Fantasy allows situations where each character's success or survival can be independent (the PCs are very rarely all on one fighting ship, meaning the campaign just ends if it is blown up), so can more reasonably be jeopardized.
- Fantasy has required gear, allows for up-scaled gear as reward, and also doesn't let 'has lots of money for gear' obviate any and all other capability.
None of these are absolute, and many individually show up in other genres. Traps that make no sense (or would cost 1000x a more deadly and sensible one) are a staple of cliffhangers and Bond-style spy capers. Sci fi settings can eliminate the 'why wouldn't I just call the authorities?' issue if the settings are isolated untamed planets where global communication isn't set up and/or there are no authorities to call. Westerns can be set up so that the doctor and the tracker contribute (and receive as much spotlight) as much as the weathered gunfighter. Make someone a zombie or throw them in
stormtrooper (or
stormtrooper) outfits and they become acceptable targets. WWII action movie genre allows gear porn without it being 'guy with best bank account wins.' However, most other games outside of fantasy have at least one of these aspects that make building a compelling game for 4-6 players (with slowly advancing characters doing interesting things and sharing in the determination of success) at least a little bit more challenging than a typical fantasy campaign.