It could be that in the context of the fanfiction, Snape believes Harry has been disrespectful towards him or other teachers. For example, if Harry were to talk back or show disobedience in class, Snape would likely punish him as a way to assert his authority.
One reason could be Harry's resemblance to his father. Snape had a long - standing grudge against James Potter, and seeing Harry might trigger those old feelings. In slash fanfiction, this can be exaggerated, with Snape being harsher on Harry because of his connection to James.
Another reason might be that Harry is suspected of sneaking around in areas where he's not supposed to be. Snape, as a vigilant teacher, may punish Harry to maintain discipline in the school. He may think Harry is up to something related to the ongoing dangerous situations in the wizarding world and wants to keep him in line.
In some fanfictions, Snape might punish Harry by giving him extra detention tasks like scrubbing the cauldrons in the Potions classroom until they shine. This is a common form of punishment as it's within Snape's domain as the Potions master.
In some fanfics, Snape might punish Harry because of his perceived insolence in class. Harry has a rebellious streak, and Snape, being strict, wouldn't tolerate any behavior that he deems disrespectful to his authority as a teacher.
Perhaps in this fanfiction, Snape shows a side of himself that is completely different from what Harry has known. He might be more open and honest with Harry, sharing secrets that make Harry believe he can be trusted. Like Snape might disclose some long - held information about Harry's parents that only he knew, which makes Harry think Snape has been on his side all along.
One reason could be Draco's arrogance. If Draco shows too much pride and disrespect in class, Snape, who values discipline, would not tolerate it. For example, if Draco mocks other students' potions attempts, Snape might punish him.
Well, if such a fanfiction exists, one possible reason could be a huge misunderstanding. Maybe Harry discovers something about Snape that he misinterprets and then hounds Snape with accusations and guilt - tripping until Snape can't take it anymore. Another reason could be if dark magic is involved in some way, like Harry is under the influence of a dark spell that makes him act out of character and target Snape relentlessly.
One possible reason could be copyright infringement. If the fanfiction uses too much of the original 'Harry Potter' material without proper authorization, J.K. Rowling (or those in charge of the franchise) might take legal action. Another reason could be if the fanfiction misrepresents the characters in a way that goes against the intended spirit of the original work.
One reason could be that he realizes Harry has a lot of potential and wants to nurture it. He sees that Harry is in a difficult position, being the target of Voldemort, and decides to help him despite their past differences.
One reason could be that the creators of such fanfiction are die - hard Snape fans. They might feel that Snape is the most interesting and underappreciated character in the 'Harry Potter' series. So, they create fanfiction where Harry Potter, who they may see as getting too much attention in the original, is not as great, to put more focus on Snape.