I can't say if this is a definitive rule of English, but in my experience there is a slightly different connotation. The word "anything" seems broader than "something". It implies that every possibility has been tried. had the text said "only Malfoy had something bad to say" we could interpret that as meaning simply that Malfoy thought of something bad to say. It doesn't necessarily imply that it was difficult to come up with something bad to say.
In contrast, "only Malfoy had anything to say" seems to imply that it was difficult to come up with something bad to say.He had exhausted all options and he was grasping at straws to find anything negative, no matter how far-fetched.
Indeed this can perhaps be supported by the very next sentence. The best thing Malfoy can come up with that is negative about Lupin is the state of his robes. The discussion was clearly about whether Lupin was a good teacher, and whether his classes were good classes. Appparently Malfoy could think of nothing bad about Lupin that was relevant, so he had to desperately come up with anything negative, even though it had nothing to do with the topic at hand.
I don't think that the word "something" would carry the same extent of the implication.