Question: how does the sword of gryffindor get to neville?
Answer: How did Neville get the sword of Gryffindor? Specifically, when Voldemort set the Sorting Hat on Neville's head and then set it alight, the sword dropped down onto Neville's head, he pulled it out and then hacked off Nagini's head. The sword and the sorting hat are definitely linked by some form of magic.