Well in military context of medieval times no one used a sword, except in cramped melee situations or as backup. Everyone has one, yes, exactly for that. Watch a bit of Matt Eastons scholagladiatora youtube channel (HEMA) and he discusses loads of this.
Great swords were often used versus horses (legs) and if two knights in plate were fighting with great swords they were used like a short spear (half sword technics) or warhammer (mordhau) by griipping them with 1 or two hands by the blade.
Only versus unarmored and lightly armored opponents swords can be used in the traditional way most people think about when thinking about swords, and be effective.
A 1 on 1 situation with equally experienced fighters IRL: spear wins 9 out of 10 times,mainly because of its reach, it attacks first, it is very hard to counter or parry, because with very little movement on the attackers side you can create big movement at the defenders side.
A sword is a civilians weapon, ineffective against most armored oponents, lacks reach and penetration power versus chain and plate, can be easily countered by a shield, requires loads of training etc. etc.
In D&D more often than not, the situation is rather a 1 vs 1 or group vs. group than a military battle formation vs another. And not all oponents wear armor or even are humanoid. So there a sword might compete a bit better.
The mystifying of the sword IRL comes because of its symbolic meaning: It was the first weapon which could not double as a tool or a hunting weapon, it was a "pure" weapon and so the choice as a status symbol for noblemen. It also could be worn quite easily in a sheat or belt at your side keeping your hands free making it a good self defense weapon with better reach than the dagger (everybody was wearing)
Again here: I bet in a duel sword vs dagger, unarmored the sword beats the dagger 9 out of ten.
Because of reach and weapon speed. Yes. A halberd even has more velocity if swung. Think about it, it is only mechanics, and circular movement and lever aka radius of the movement (which is a accelerated movement by itself).