Sometimes, it could be due to Harry's defiant attitude towards Snape. Harry may openly question Snape's authority or teaching methods, which angers Snape and leads to punishment. Snape has his own pride and way of doing things, and he won't let a student, even one as important as Harry, undermine his position.
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 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.
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.
One possible reason could be that Snape fails to deliver crucial information. Voldemort is a very demanding and unforgiving master. If Snape doesn't give him accurate details about the Order of the Phoenix's plans, for example, Voldemort would surely be enraged and punish him.
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.
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 common reason could be his love for Lily. Since Harry is Lily's son, Snape might feel an obligation to protect him out of his undying love for her. It's like he's trying to preserve a part of Lily that still exists in the world through Harry.
However, as the story progresses, Harry may start to understand the reasons behind Snape's actions. He could become more resigned and accept the punishment as a part of his growth. He might use the experience to become more cautious in his actions and more respectful of the rules.
One common reason is Snape's lingering hatred for James Potter. Since Harry looks so much like his father, Snape might take out his old grudges on Harry. He sees James in Harry and can't help but be reminded of the past bullying and his unrequited love for Lily. So, he acts hurtfully towards Harry as a way to get back at James, even if it's not really fair to Harry.
One common scenario could be that Harry is caught sneaking around the Slytherin common room or stealing potions ingredients from Snape's stores. So, Snape and Draco might make him do extra detention tasks like scrubbing the cauldrons for hours without magic. Another situation could be if Harry is suspected of cheating in a Potions exam. Draco might report it to Snape, and they could punish Harry by making him redo all his Potions experiments from the semester.
At first, Harry is likely to be angry. He might feel that Snape is being unfair and targeting him. Harry has a strong sense of justice, and when he believes he's being wrongly punished, he'll be resentful.