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.
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.
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 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.
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.
Harry's reaction can be complex. At first, he may show immediate resistance, arguing that he's been wrongly accused. When he realizes that arguing won't get him anywhere, he might become sullen and withdrawn. However, this sullenness is also a sign of his determination not to let them break his spirit. He'll keep thinking of ways to prove his innocence or to show that their punishment is unjust. In some fanfictions, Harry also uses these punishments as a motivation to become better at magic, so that he can one day stand up to Snape and Draco more effectively.
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.
He might give Harry detention. Harry could be made to clean the trophies in the trophy room or help Hagrid with some difficult tasks in the Forbidden Forest under strict supervision.
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.
Harry could try to talk to Dumbledore about it. Dumbledore has a lot of influence and might be able to make Snape see the error of his ways.