The Sorting Hat takes your choice into account, but it doesn’t always give you what you want. Harry was able to choose Gryffindor over Slytherin, but Neville was put in Gryffindor despite his preference for Hufflepuff.
In Neville’s case, the Hat was determined to place him in Gryffindor: Neville, intimidated by that house’s reputation for bravery, requested a placing in Hufflepuff. Their silent wrangling resulted in triumph for the Hat. – Pottermore
It’s easy to imagine Neville as a Hufflepuff. Even aside from the fact that Helga Hufflepuff took all the students the other founders rejected, and would have accepted him regardless, he’s a pretty good embodiment of Hufflepuff traits. He is down-to-earth, humble, and generous. He’s hard-working and always seems to try his best despite not doing very well in his classes. He certainly values fairness and justice, and he’s less-inclined to break the rules than some of his Gryffindor peers. Meanwhile, he spends the first six books as a timid, awkward, easily-overlooked kid who seems utterly out-of-place in Gryffindor. While he does show some signs of bravery, such as standing up to the trio in Sorcerer’s Stone and joining Dumbledore’s Army in Order of the Phoenix, it’s hard to say at that point that Neville is defined by his bravery. It’s not until Deathly Hallows, a full seven years after the sorting ceremony, that his true heroism begins to show.
So why, then, did the hat refuse to put him in Hufflepuff when it’s honored similar requests before? His preference was different from Harry’s in one very important way. While Harry asked not to be a Slytherin because he knew of their reputation for dark magic and evil, Neville was just intimidated by Gryffindor, not repulsed by it. He didn’t think he was good enough for Gryffindor and thought he would have to settle for Hufflepuff in order to avoid embarrassing himself. Putting Harry in Slytherin would have meant dismissing his values and denying him a choice. Putting Neville in Gryffindor, on the other hand, was a vote of confidence.
In many cases where a character doesn’t quite live up to what their house is supposed to stand for, I think we can assume the hat was trying to give them a chance for growth. For instance, Peter Pettigrew is a cowardly Gryffindor, but he was almost certainly placed there because the hat saw his admiration of his more heroic friends and hoped he could become more like them. Gilderoy Lockhart is an incompetent Ravenclaw, but his skill as a writer indicates intelligence and creativity that could have been put to better use. On a more positive note, Hermione grows from a stuck-up know-it-all to a courageous young woman as a result of her time in Gryffindor. It’s as if the sorting hat can see not just a person’s potential but where they’ll have the best chance of reaching their full potential as well.
Neville didn’t truly want to be a Hufflepuff or value Hufflepuff work ethic and fairness over Gryffindor bravery. He simply wasn’t ready yet to accept his own potential, and as a Hufflepuff, might never have embraced it. Being placed there would only have confirmed his fears of inadequacy, while being sorted into Gryffindor gave him a chance to grow in confidence and courage.
Or, in other words, the Sorting Hat takes your choice into account if you want it for the right reasons. It takes your choice into account if your value system doesn’t match up to a house you’re suited for, if you have a deep personal reason for what you want, or if your choice will give you a chance to grow into a better person. It doesn’t take your choice into account if your choice would limit you. Neville did value bravery and heroism and was simply afraid he’d never be capable of them, so by putting him in Gryffindor, the hat made sure that he would.