It is never stated in the book, but J.K Rowling has later said that because Neville is a true Gryffindor he was able to pull the sword out of the Sorting Hat.
Actually it did say. The sorting hat was put on Neville and set on fire by Voldemort and when the full body bind broke he pulled the sword from the hat.
Ahhh, that makes sense...I must've read right past that. I read the book so fast, i should read it again to see what else i missed
Thanks!!!