Hagrid was generalizing - he probably wasn’t intending precision.
When Hagrid said “there wasn’t a single witch or wizard who went bad who wasn’t in Slytherin”, he wasn’t likely intending precision or complete accuracy. Hagrid probably knew of a lot of Dark wizards from Slytherin, so told Harry they’re all from Slytherin without stopping to check the accuracy of what he was saying.
“School houses. There’s four. Everyone says Hufflepuff are a lot o’ duffers, but –’
‘I bet I’m in Hufflepuff,’ said Harry gloomily.
‘Better Hufflepuff than Slytherin,’ said Hagrid darkly. ‘There’s not a single witch or wizard who went bad who wasn’t in Slytherin. You-Know-Who was one.’
‘Vol– sorry – You-Know-Who was at Hogwarts?’
‘Years an’ years ago,’ said Hagrid.”
- Harry Potter and the Philosopher's Stone, Chapter 5 (Diagon Alley)
Quite a few Dark wizards were in Slytherin, so it’s not entirely unfounded - it just doesn’t hold up to close scrutiny, since there are counter-examples. The way he put it, it can be disproved by only one example of a Dark wizard from another house. People with analytical minds tend to avoid making absolute statements for exactly this reason. However, Hagrid says what he thinks but doesn’t always think about what he says. It’s likely that Hagrid simply couldn’t think of any Dark wizards from another house, and associated Slytherin with Dark wizards, so made his statement to Harry based on that.
In addition, he’s not really the type to mentally double-check what he says, it’s unlikely he was listing all the Dark wizards he knew in his mind to make sure none were in another house. He was trying to explain Hogwarts houses to Harry, who knew absolutely nothing about them - since Hagrid didn’t think Slytherin was a good house to be in, that would come across when he’s trying to give Harry descriptions of the houses and what they represent. Hagrid himself knew of one counter-example (though it turned out to be false) since he thought he knew Sirius was the one who betrayed the Potters. He definitely knew this, and hated Sirius for his supposed betrayal. He also knew Sirius was a Gryffindor, so he would know the person who (supposedly) betrayed the Potters and killed Muggles and Pettigrew wasn’t a Slytherin.
“Jus’ got him outta the ruins, poor little thing, with a great slash across his forehead, an’ his parents dead … an’ Sirius Black turns up, on that flyin’ motorbike he used ter ride. Never occurred ter me what he was doin’ there. I didn’ know he’d bin Lily an’ James’s Secret Keeper. Thought he’d jus’ heard the news o’ You-Know-Who’s attack an’ come ter see what he could do. White an’ shakin’, he was. An’ yeh know what I did? I COMFORTED THE MURDERIN’ TRAITOR!’ Hagrid roared.”
- Harry Potter and the Prisoner of Azkaban, Chapter 10 (The Marauder’s Map)
Hagrid does have a tendency to make broad generalizations, without considering the precise accuracy of his statements. He also says no Malfoy is worth listening to - it’s impossible to think that he could have met every single Malfoy and know for a fact that they’re all not worth listening to. There may be a Malfoy who is to that family what Sirius is to the Black family, a pariah who rejects the ideals the rest of the family believes in, but Hagrid is most likely simply referring to the Malfoys he knows and thinks of first upon hearing the name.
“Yeh should’ve ignored him, Arthur,’ said Hagrid, almost lifting Mr Weasley off his feet as he straightened his robes. ‘Rotten ter the core, the whole family, everyone knows that. No Malfoy’s worth listenin’ ter. Bad blood, that’s what it is. Come on now – let’s get outta here.”
- Harry Potter and the Chamber of Secrets, Chapter 4 (At Flourish and Blotts)
This is another good example of something that’s probably mostly true (at least from the perspective of the protagonists), but as an absolute statement, can be disproved by one Malfoy who doesn’t share pure-blood ideals.