A somewhat trite answer would be: because history says so
A
basic sword is very easy to make, and relatively material efficient. It's a flat bit of metal with a sharp edge, hopefully harder (whether by material or manufacture) than whatever your enemy has.
Thus they can be mass produced to equip your army relatively easily.
See also spears: get some wood, whittle a lot, stick a spike/flint/whatever on the end and you're done.
I'd imagine that's the simplest reason why they were so prevalent in history, right there. There's no real reason why even the most fantastical world would be any different unless either the balance of material available in the world, or the abundance of 'power' (magic or something else) is enough to make a martial weapon largely pointless.
Note also that they're ideal for the close crush that armies used to fight in at that time. Axes need more swing, maces need more material and both are a bit more unwieldy due to mass distribution (though a heavy mace is of course more suitable than a sword against metal armour).
However, for an individual, which is what a character in a book will
tend to be, there's no reason at all why they HAVE to have a sword, but it'll still likely be the most common thing out there (probably)
Personally, I'm with Bowler1. I'd rather have a Halberd or Naginata of some description. (though with some short range weapon to back it up in case someone's right in your face of course
)