In such a fanfic, one possible reason could be extreme depression. Maybe he faced overwhelming losses like the death of his closest friends and felt he couldn't go on. Another reason might be that he was under some kind of dark magic influence that made him lose his will to live.
Perhaps in the 'harry kills himself fanfic', he was burdened by the great expectations placed on him. Everyone saw him as the savior, and the pressure became too much. He might have thought that by ending his life, he could escape all the responsibilities and the constant danger he was in.
One possible reason could be extreme despair. Maybe in that fanfic's alternate universe, Harry has lost all his friends and loved ones in a very tragic way, like a second wizarding war that was far more brutal and unforgiving. He might see no way out of the emotional pain and thus choose to end his own life.
Creative exploration. Some writers might want to see how the story would change if Harry had a darker side.
Well, some writers might be interested in exploring alternate timelines or universes. In a different reality, they might think that Harry could be influenced by dark forces in such a way that he would do something as horrible as killing his parents. It could also be a form of creative rebellion against the established story. They want to break the rules and see where it takes them. And maybe, for some, it's a way to deal with complex psychological concepts, like how a person can lose their moral compass completely.
One possible reason could be a misdirected spell during a battle. In the heat of a fight, Harry's spell could go awry and accidentally kill Malfoy. Another reason might be if Malfoy was under the control of a dark wizard and was about to do something truly terrible, and Harry had to stop him at all costs, including taking his life.
It could be because of a dark power corrupting Sasuke. Maybe an ancient evil force takes over him and makes him see Sakura as an enemy. In some fanfics, this kind of external influence can completely change a character's actions. Also, it might be related to Sasuke's pursuit of power. If he believes Sakura is standing in the way of his ultimate power - seeking goal, he could be driven to kill her.
One possible reason could be extreme despair. Maybe he faced some overwhelming challenges or betrayals that made him feel there was no way out. For example, if he lost all his friends and felt completely alone in the world of the fanfic.
Some writers might want to explore the darker side of the character. They could be curious about how Harry would be if he was pushed to his limits and had to kill in self - defense or to protect others in a very extreme situation.
In some fanfictions, the power dynamics might be shifted. Maybe Lucius has become more powerful and is on the verge of destroying the wizarding world as Harry knows it. Harry, seeing no other way to stop him, decides to kill Lucius. It could also be a way for the writer to explore the darker side of Harry's character, showing what he could become when pushed to his limits and faced with an unrelenting enemy like Lucius.
Well, it could be that he has lost all hope. In the fanfiction world, if the situation becomes so dire that he sees no way out for himself or the people he loves. For example, if Voldemort manages to gain complete control and Harry Potter thinks his sacrifice by taking his own life might be the ultimate solution to break Voldemort's power. He might also be suffering from post - traumatic stress after all the battles and losses, leading him to this extreme decision.
One possible reason could be mind control. Some dark power might take over Naruto's mind and force him to turn on Jiraiya without his own will.