Your House can represent traits you value, not necessarily have.
This is a good explanation for all the Sortings that that don't seem to match up with the student's traits. Peter Pettigrew could have been a Gryffindor because he wanted to be brave, not because he was. Although he did develop courage later on, unlike Pettigrew, the same thing could be said for Neville Longbottom. Hermione Granger would have probably been a Ravenclaw based solely on her traits, but apparently she valued bravery more, as evidenced by her telling Harry that friendship and bravery were more important than books and cleverness.
“I’m not as good as you,’ said Harry, very embarrassed, as she let go of him.
‘Me!’ said Hermione. ‘Books! And cleverness! There are more important things – friendship and bravery and – oh Harry – be careful!”
- Harry Potter and the Philosopher's Stone, Chapter 16 (Through the Trapdoor)
There, she basically stated herself that she valued Gryffindor traits over Ravenclaw traits.
Students also tend to be put in the house they want to be in most.
Choice also is a part of each Sorting, so if someone wants badly enough to be in a particular House, then they probably will be. Hermione showed a clear preference for Gryffindor over Ravenclaw when she was talking to Ron and Harry on the Hogwarts Express.
“I’ve been asking around and I hope I’m in Gryffindor, it sounds by far the best, I hear Dumbledore himself was one, but I suppose Ravenclaw wouldn’t be too bad …”
- Harry Potter and the Philosopher's Stone, Chapter 6 (The Journey from Platform Nine and Three-Quarters)
There's never been a case where a student is shown to be thoroughly unhappy with their Hogwarts House in the seven books, so it seems likely that the Sorting Hat does place some importance on the student's opinions. There’s also never been a case in the seven books where a student really wants a particular house and is sorted elsewhere.
Out-of-universe answer - Rowling wanted all the bad guys to be in Slytherin.
Over the course of the series, Slytherin is used as the 'evil' House, where everyone bad goes whether they have cunning and ambition or not. Some of them did actually have Slytherin traits - like the Dark Lord himself, who was undeniably both cunning and ambitious. However, others, like Crabbe and Goyle, had none of the defining Slytherin traits. But to fit the idea of Slytherin being the 'evil' House, they were put in Slytherin without any further thought as to why they belonged there other than that they were the bad guys.