Neville retrieved it from the Sorting Hat just as Harry had, so perhaps this theory is correct in saying that whenever a true Gryffindor has need of the sword it appears (as Dumbledore said to Harry after the Chamber of Secrets debacle).
Although the Goblins felt that the sword was rightfully theirs after Godric Gryffindor's death, presumably the sword did not feel the same way and left Griphook when Neville needed it.
scifi.stackexchange.com/users/1470/Matthew Read
The hat acts as a portal to transport the sword
The Sorting Hat has another ability, which has rarely been revealed to anyone at Hogwarts.
It is a magical portal, by which another of Godric Gryffindor’s possessions may be accessed: the sword of Gryffindor.
This sword was enchanted by Godric to appear whenever a member of his house asks for help while wearing the Hat.
Twice, in the course of the Harry Potter series, the sword is transported from a temporary owner to aid a Gryffindor who needs a weapon.
Pottermore - The Sorting Hat
(behind paywall)
scifi.stackexchange.com/users/55866/ibid
In the movie the sword materialises (from the hat??), which backs up the "it shows up just as a true Gryffindor needs it" idea.
In Pottermore [SPOILER] JKR writes about the Sorting Hat being very adamant about placing Neville in Gryffindor (despite his hesitations), which adds some credence to "true Gryffindor".
scifi.stackexchange.com/users/None/
I believe either the goblin who produced the sword to Godric Gryffindor's specifications, or Godric Gryffindor himself added the magic which would make the sword appear to a worthy Gryffindor in need.
I'm leaning towards Gryffindor himself, because I'm sure the goblin would have been reluctant to do so, or would have made it somehow stop with Gryffindor's death.
I'm not sure that's possible, so I believe it was Gryffindor, who was a powerful wizard, who did it.
scifi.stackexchange.com/users/80053/Bonnie
In one swift, fluid motion, Neville broke free of the Body-Bind Curse upon him; the flaming hat fell off him and he drew from its depths something silver, with a glittering, rubied handle...
(Harry Potter and the Deathly Hallows) .
Neville exhibited the courage of a true Gryffindor.
And since the sword shows up to help a true Gryffindor who is in need of it (just as it did for Harry in the Chamber of Secrets), it came to Neville's rescue.
scifi.stackexchange.com/users/90742/Lucifer
I recently read the final book of the series. At one point was the vault heist, where the goblin Griphook runs off with the Sword of Gryffindor. Yet near the end of the book, Neville Longbottom suddenly has the sword and uses it to defeat the snake Nagini.  How could this be possible? Griphook wanted the sword because it was goblin-made, so I doubt he would given it over to any non-goblin. How does Neville suddenly get the sword?
How does Neville Longbottom get the Sword of Gryffindor?
scifi.stackexchange.com
<harry-potter>
scifi.stackexchange.com/questions/15807
scifi.stackexchange.com/users/6109/Grant Palin
Some people believe it was Gryffindor, who was a powerful wizard, had to sword produced to his specifications, or Godric Gryffindor himself added the magic which would make the sword appear to a worthy Gryffindor in need (as Dumbledore explained to Harry in the Chamber of Secrets). It is said that Neville retrieved it from the Sorting Hat just as Harry had, as a true Gryffindor. Neville retrieves the sword from the Sorting Hat — it just shows up when he needs it. 
Neville retrieves the sword from the Sorting Hat — it just shows up when he needs it. 