Question: how did the sword of gryffindor get back to hogwarts?
Answer: Neville pulled the sword out from inside the Sorting Hat. After Griphook took the Sword of Gryffindor from Harry, it was with Griphook until Neville pulled it out of the Sorting Hat when the Dark Lord had put the hat on him. Neville was able to get the sword the same way Harry did - by being a worthy Gryffindor.