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 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.
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.
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 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 Harry is afraid of Snape's intimidating presence. Snape has always been strict and rather unfriendly towards Harry in the original series, so in the fanfiction, this fear might be amplified, causing Harry to run. Another reason could be that Harry has stumbled upon something he shouldn't have seen that involves Snape, and he's running to avoid getting caught.
One possible reason could be Snape's sense of duty to protect Hogwarts students in general. Even though he dislikes Harry, he might put aside personal feelings to ensure the safety of a student in a dangerous tournament like the Triwizard Tournament. Another reason could be Dumbledore's influence. Dumbledore trusts Snape and may have asked him to keep an eye on Harry during this event.
One possible reason could be Snape's lingering resentment towards James Potter, Harry's father. Snape might see Harry as a reminder of the bullying he endured from James during their school days. So, he takes out his anger on Harry.