One possible reason could be that he's been influenced by some dark magic or a spell that makes him act out of character. Another reason might be extreme jealousy, say if Hermione is getting more recognition in the wizarding world than him for some time and he lashes out in a moment of weakness.
It could be due to a misunderstanding. Maybe he overhears something about Hermione that he misinterprets completely. Or he could be influenced by a false prophecy or some misinformation that makes him think Hermione has some sort of ulterior motive that he wrongly associates with her Muggle - born status. Also, if there's a rift in their group of friends and he feels like Hermione is on the 'wrong' side of an argument, in a fit of anger, he might use the offensive term.
One possible reason could be jealousy. Maybe Ginny is jealous of Hermione's intelligence or her close relationship with Harry. So, out of spite, she uses the slur.
One possible reason could be to create drama. Fanfiction often takes the existing relationships and twists them for the sake of a more engaging story. Maybe the author wants to explore how Hermione would react to such a hurtful comment from Ron, and how it would impact their friendship or potential romantic relationship.
It could be that Dumbledore has been lying to Harry about his own family. For example, if Dumbledore knew more about Harry's connection to the Peverell family and kept it from him. Harry would feel betrayed and might lash out with such a harsh statement.
In fanfiction, it could be part of a developing relationship. If the author is exploring a romantic angle between Harry and Hermione, a touch in class could be a subtle way of showing their growing closeness. It could also be a way to show their strong friendship. For example, they might be working on a group project in class and Harry touches Hermione's hand to pass her a needed ingredient or tool, which shows their seamless cooperation and deep bond.
It could be due to a misunderstanding. Suppose Ron overhears a conversation between Harry and Hermione that he misinterprets completely. He might think they are plotting against him or don't really consider him a true friend. So in a fit of anger and hurt, he decides to betray them.
One reason could be his status as the Boy Who Lived. In the original story, Harry has this special aura about him, and in fanfiction, Hermione might be drawn to that in an obsessive way. Also, his bravery and leadership qualities could be factors that make Hermione overly interested in him.
Another reason could be a rift in their friendship caused by outside factors. For instance, if the wizarding community starts to turn against Harry because of false rumors or misinformation, Hermione might find it too difficult to stand by him. She may fear for her own reputation or safety, and this could lead to her abandoning Harry.
It could also be due to a series of unlucky events. Suppose Hermione's well - intentioned plans keep backfiring in a way that makes Harry question her judgment. Like when she tries to solve a problem but ends up making it worse, Harry might start to lose trust.
Another reason could be that there are some misunderstandings between them. For example, Hermione might misinterpret Harry's actions or words as being too reckless or irresponsible, and she decides to push him away to avoid being dragged into what she perceives as a bad situation. Also, it could be related to her own insecurities. She might feel that she is holding Harry back in some way or that their friendship is becoming too complicated, so she takes the step of pushing him away to simplify things.
One possible reason could be that she is in a desperate situation. Maybe she needs something for a very important spell or potion to save someone's life and she thinks Harry won't notice or will forgive her. For example, if there is a rare ingredient that only Harry has access to and time is running out.