He could have been influenced by the Muggle world. Having grown up with Muggles, he might have seen the power of guns and thought it could be a more straightforward solution compared to complex magic spells. Also, he might have wanted to prove that Muggle technology could be just as effective in the wizarding world's battles.
It's possible that there's a hidden stash of Muggle items in Hogwarts, and Harry stumbles upon it. He discovers the gun there, realizes it could be a powerful weapon against Voldemort, and decides to use it.
Some might be shocked. Hermione, for example, would probably be very concerned about the use of a Muggle weapon in the wizarding world and its implications. She might worry about how it could change the balance between the Muggle and wizarding communities.
Well, it would change the whole wizarding world's concept of combat. Guns are a Muggle weapon, so it would show that Muggle technology could be a real threat to wizards. Maybe it would make the wizarding community more open to learning about Muggle ways.
The wizarding community would be shocked. Guns are not part of their world, and for Harry to use one to kill Voldemort would be unthinkable for many. There would be outrage from some traditional wizards who believe in magic as the only proper way to fight.
The wizarding world would likely be in a state of shock and then celebration. People would start to see Azkaban in a new light, perhaps no longer as just a place of horror but also as the site where the great evil was finally vanquished.
Perhaps in this fanfic, there has been some major plot twist that makes Harry believe that bowing to Voldemort is the only way to save his friends or the wizarding world. For example, Voldemort may have threatened to kill all of Harry's loved ones if he doesn't submit, and Harry is sacrificing his pride for the greater good.
After Harry kills Voldemort in the graveyard in the fanfiction, the magical balance might shift. With Voldemort gone, some of the dark magic that was prevalent might start to fade away. The Hogwarts School of Witchcraft and Wizardry could see a new golden age. New spells and magical theories might be explored as the fear of Voldemort no longer holds back the wizarding scholars. Harry himself might start to travel around the world to spread the news of Voldemort's defeat and also to learn more about different types of magic. His friends would also have new opportunities, like Hermione might be able to further her studies without the constant threat of Voldemort and Ron could finally relax and enjoy a more peaceful life at the Burrow.
A wizard who has dabbled in the Muggle world might give Harry a gun. This wizard could have seen the potential use of a Muggle weapon in the wizarding world's dangerous situations.
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.
Perhaps Harry discovers some dark secret about his own past or powers that he thinks only Voldemort can help him understand. For example, if he finds out that his connection to Voldemort is more complex than he thought and that Voldemort holds the key to unlocking or controlling certain aspects of his own magic.