One reason could be his sense of duty. Despite his dislike for Harry on the surface, he might still feel responsible for the safety of all students at Hogwarts, including Harry. So when he sees Harry in danger from Dementors, he steps in to save him.
Well, it could be that Snape has been secretly keeping an eye on Harry all along. In the fanfiction world, he might have developed a new spell or potion specifically designed to counter the effects of Dementors. When he sees Harry in danger, he uses this new creation to save him. For example, he could have a potion that creates a protective shield around Harry, preventing the Dementors from getting close enough to suck out his soul.
One possible reason could be that Snape still has an underlying sense of loyalty to Dumbledore. Since Dumbledore cares about Harry, Snape might step in to save him from Umbridge's cruelty. He doesn't want to see Hogwarts turned into a place of unjust persecution under Umbridge's regime, and Harry is a symbol of the resistance against that.
Snape might do it out of his love for Lily. Since Harry is Lily's son, he feels a sense of obligation to protect 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 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.
One possible reason could be that Snape sees Hermione's value as a brilliant student. He might recognize her potential and not want it to be wasted just because of her dad's actions or situation. Maybe he has a sense of justice deep down, despite his often cold exterior.
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.
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.
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.