In some fanfictions, it could be related to Snape's loyalty to Dumbledore. If Snape believes Harry is endangering a secret plan that Dumbledore has set in motion, he might punch Harry to stop him from doing something stupid. For example, if Harry is about to reveal a crucial piece of information to the wrong person.
One possible reason could be Snape's long - standing grudge against James Potter, Harry's father. Since Snape had a difficult past with James, he might project that onto Harry. Another reason could be that Snape is trying to protect Harry in a very strange way. He may think that by rejecting Harry, he is keeping him at a distance from the dangerous wizarding world politics and plots that Snape is often involved in.
One reason could be Harry's fame. Since he's known as 'The Boy Who Lived', Snape might think he gets special treatment because of it. He could see the attention Harry gets from the other students and teachers as spoiling him.
Well, perhaps there was an emergency at Hogwarts. Maybe some dark forces were approaching, and Snape, being a powerful wizard and a Hogwarts professor, felt it was his responsibility to pick Harry up. Harry was always a target for the dark side. Also, it could be that Snape had some new information about Harry's family or his destiny that made him decide to take Harry under his wing, so to speak, by picking him up.
Snape could be distracted by his own dark thoughts or memories. For example, if something reminded him of his past with James Potter, his hatred for Harry's father might cloud his judgment for a moment and cause him to accidentally cast a spell in Harry's direction.
One possible reason could be Snape's personal bias against Harry. Since Harry is James Potter's son, and Snape had a difficult relationship with James in their school days, Snape might unconsciously take out his old grudges on Harry.
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 could be that Snape suspects Harry of some secret knowledge or activity. In the complex world of fanfiction, there could be hidden plots where Harry is involved in something that Snape is trying to uncover. By fingering Harry in class, he's trying to rattle Harry and get him to reveal something, either through his words or his actions during the class.
One possible reason could be his lingering resentment towards James Potter, Harry's father. Snape and James had a long - standing feud during their school days. Since Harry looks a lot like James, Snape might be transferring his old grudges onto Harry.
One possible reason could be that Snape shows a different side to Harry in the fanfiction. Maybe he protects Harry secretly from some hidden threats that others are unaware of, which makes Harry start to trust him.
One possible reason could be that Snape is trying to intimidate Harry. He has always had a rather tense relationship with Harry in the original story, and this could be an extreme form of showing his authority. Maybe he suspects Harry of something, like being involved in some mischief or having knowledge about a certain Dark Arts item or activity.