Wow, there’s a lot of weapon vs. weapon trash talking going on here. Couple things:
First of all, no weapon beats any other weapon 100% of the time, even assuming one-on-one combat between “equally skilled” opponents (and “equally skilled” is pretty difficult to define when talking about two different kinds of weapons.) Context is always king.
If we put swords and polearms both in their proper context, it is clear that they would very rarely be used against each other, with the possible exception of big two-handed swords like the montante, though that is debated among scholars.
Swords were really not primary battlefield weapons, again, save maybe two-handers. One-handed swords and longswords were used as sidearms on the battlefield, as civilian self-defense weapons, and as dueling and tournament weapons. This is because their primary advantages are being easy to carry around, and highly versatile.
Polearms were primarily formation weapons, used on the battlefield effectively as area denial. Line up a bunch of guys with long pointy sticks and tell them to move as a unit, and it’s going to be very difficult for anyone to get past their line without intimidating them into breaking formation. Put some guys with bows or guns behind them, and you’ve got a solid attack and defense force. Give those guys swords, and they can defend themselves in close-quarters if the pike line gets broken. Polearms were almost never used in civilian self-defense because they’re big and hard to carry around. They did see use in dueling and tournaments, but usually paired up against other polearm users.
The two-handed sword is a bit of an odd duck. It has the silhouette of a sword, but the length of a (very short) polearm. It is therefore unlikely to have been used in the same contexts as other swords, but there isn’t really evidence of it being used in formation like a polearm. There is some suggestion that it could have been used specifically to break up polearm formations, but there really isn’t a lot of surviving material describing how to use it. What we do see in montante manuals is a fighting style that employs huge sweeping movements and keeping up momentum, so it was probably its own beast altogether. Some scholars have suggested that it may have been made to be used by one well-trained man at arms to defend against many less-skilled conscripts. A montante user swinging his giant sword around becomes a one-man zone of denial, but he’s better at holding a choke point than advancing on a group of pikemen.
So, to reiterate, there is very little historical context in which sword-vs-spear would have even happened. In the events that it did, the primary advantage of the spear is its reach, which a skilled spear user would be able to exploit to its fullest. Reach is one of the most valuable attributes for a medieval weapon to have. The primary advantage of the sword is really in its portability, though a secondary advantage is its versatility. Where a spear is deadliest at its tip and can be grappled along most of its length, you can threaten with pretty much any part of a sword. Still, to use it effectively against someone with a spear you need to close the distance, and that can be very difficult to do safely.
For folks who have LARP experience and have found sword users consistently able to press spear users, keep in mind you are in a low-stakes simulacrum of medieval combat. Try it with live steel instead of padded boffers and I expect the sword-user will be much less bold in advancing. Especially if he thinks the spear-user is actually trying to kill him.