The goalposts have been dragged around this thread since the beginning. Of course, the initial premise isn't well defined, so it is pretty much no man's land. Rapiers are concurrent with or precede other products listed in the equipment lists, were used on battlefields (and the only D&D game that only included weapons specific to war was Chainmail/oD&D, so this seems a non sequitur right out the gate), and are no less appropriate to fighting fantasy megabeasts than most of the rest of the weapon list as well. The whole thread is kind of a non sequitur, too, as 'this isn't realistically good for fighting a dragon' is incredibly loosely connected to the notion of whether it belongs in D&D (which has always been about a lot more than that, including non-battlefield person-to-person combat, where a rapier is entirely appropriate) to begin with.
OP doesn't like rapiers in D&D. Good, done. If we'd started with premises based on theme or tone, we'd have something useful to do here. Instead we got a competitive 'I bet I have more amateur historical warfare knowledge than you'-style pissing match. I've seen those since Usenet and Dragonsfoot back in the early/ mid-90s, and have yet to see anyone actually be impressive doing so. It's a slight iteration of the 'yeah, well I have 5 years of Ti Kwan Leep, which is better than your 4 years of SCA at knowing who would win in a fight' we all did as awkward teenagers. At least we've gotten some interesting house rule discussions in on the side.
What about having certain creatures (i.e. dragons with their scales) absorb the first few HP of damage from each slashing, bludgeoning or piercing attack? If 100 zero-level farmers manage to score a few hits with their clubs and spears, and on average they do 3-4 HP damage each, most wouldn't end up inflicting any damage at all, or perhaps a point or two.
They have that (damage thresholds) for objects. Likewise, that's pretty much D&D 3.0/3.5/PF1 Damage resistance minus that unlikely scenario that the zero-level farmers had magic weapons. There were mechanical reason this got removed for 5e (probably weighting of 'one big attack' vs. 'many smaller-damage attacks' classes), but could be brought back in with sufficient playtesting (or, since this is a D&D general thread, just play 3e/pf).
Rapiers in D&D. A source of concern since 2000. Time truly is a flat circle.
They were in 2e as well. There I think the concern was that they didn't do enough damage to justify the proficiency, and wouldn't show up on the magic weapon table (a concern for anything introduced after the DMG).