The sword was made to Godric Gryffindor’s specifications by Ragnuk the First, finest of the goblin silversmiths, and therefore King (in goblin culture, the ruler does not work less than the others, but more skilfully). When it was finished, Ragnuk coveted it so much that he pretended that Gryffindor had stolen it from him, and sent minions to steal it back. Gryffindor defended himself with his wand, but did not kill his attackers. Instead he sent them back to their king bewitched, to deliver the threat that if he ever tried to steal from Gryffindor again, Gryffindor would unsheathe the sword against them all.
The goblin king took the threat seriously and left Gryffindor in possession of his rightful property, but remained resentful until he died. This was the foundation for the false legend of Gryffindor’s theft that persists, in some sections of the goblin community, to this day.
The question of why a wizard would need a sword, though often asked, is easily answered. In the days before the International Statute of Secrecy, when wizards mingled freely with Muggles, they would use swords to defend themselves just as often as wands. Indeed, it was considered unsporting to use a wand against a Muggle sword (which is not to say it was never done). Many gifted wizards were also accomplished duellists in the conventional sense, Gryffindor among them.
There have been many enchanted swords in folklore. The Sword of Nuadu, part of the four legendary treasures of Tuatha Dé Danann, was invincible when drawn. Gryffindor’s sword owes something to the legend of Excalibur, the sword of King Arthur, which in some legends must be drawn from a stone by the rightful king. The idea of fitness to carry the sword is echoed in the sword of Gryffindor’s return to worthy members of its true owner’s house.
There is a further allusion to Excalibur emerging from the lake when Harry must dive into a frozen forest pool to retrieve the sword in Deathly Hallows (though the location of the sword was really due to a spiteful impulse of Snape’s to place it there), for in other versions of the legend, Excalibur was given to Arthur by the Lady of the Lake, and was returned to the lake when he died.
Within the magical world, physical possession is not necessarily a guarantee of ownership. This concept applies to the three Deathly Hallows, and also to Gryffindor’s sword.
I am interested in what happens when cultural beliefs collide. In the Harry Potter books, the most militant of the goblin race consider all goblin-made objects to be theirs by right, although a specific object might be made over to a wizard for his lifespan upon a payment of gold. Witches and wizards, like Muggles, believe that once payment has been made, the object belongs to them and their descendants or legatees in perpetuity. This is a clash of values without a solution, because each side has a different concept of what is right. It therefore presents Harry with a difficult moral dilemma when Griphook demands the sword as payment for his services in Deathly Hallows.