It does have a lot to do with personality, but the Sorting Hat also looks at your legacy. Perhaps you appear to be a Hufflepuff prima facie, but the Sorting Hat knows your family has a history of Gryffindor, and it sees something deep inside you that makes you a Gryffindor. Take Neville for example. He is very much a Hufflepuff by nature, but by the end of the series, his bravery and courage is realized. That's why he was a Gryffindor, the Sorting Hat saw something in him that he was destined to become.
Personality is environmental though. You are like your parents, in one way or another. And in the wizarding world, your legacy is all you have. Your name. It is in a child's natire to want to appease and impress your parents. And the Sorting Hat gives you a choice, just as Harry tells Albus at the end of DH2. Scorpius may have the personality of a Hufflepuff, but maybe he has a destiny to be Slytherin or he just wanted his father to be proud of him and chose Slytherin.
I think the fact that Draco raises Scorpius better than Lucius or Abraxas did would make Scorpius want his father's approval even more. And no, not all children are like that, but this doesn't take place in America. These kids were raised in early 2000s Britain. And before you say that doesn't matter, it certainly does. Especially for a wizard. Children there are raised to be more proper and respectful, at least during the late '90s and early 2000s. Children were raised more proper and respectful back then. And for a young wizard pressured with the legacy of dozens of generations, it makes a huge difference.