Well, perhaps during one of his adventures outside of Hogwarts, like when he was exploring some ancient ruins. There could have been a magical trap and as he overcame it, the Infinity Gauntlet was his reward. It could also be that some dark wizard had it and Harry defeated him in a duel and took it as a trophy.
He might find it in a hidden chamber in Hogwarts. Maybe it was left there by a powerful wizard from long ago who had some connection to other universes.
He could gain the power to control time, which would be really useful in the wizarding world. He could go back and prevent some of the bad things that happened, like the death of his parents.
The plot might involve Harry accidentally stumbling upon the Infinity Gauntlet in the Room of Requirement. As he tries to figure out what it is, he discovers its immense power. However, the Ministry of Magic wants to use it for their own gain. Harry has to decide whether to keep it safe from the Ministry or use it himself to finally defeat all the dark forces that still lurk in the wizarding world.
In this fanfiction, Harry Potter could obtain Gungnir in a rather unexpected way. For example, due to a time - traveling incident. He might accidentally travel to a different time and place where Gungnir exists. There, he could be in a situation where he has to help the local magical community. As a result of his heroic deeds, the keepers of Gungnir decide to entrust him with it. And when he returns to his own time, he brings Gungnir with him, ready to use it in his fight against the dark forces.
In some fanfictions, he might find it in the Forbidden Forest during one of his adventures. Maybe while exploring the deeper parts of the forest that are off - limits to most students, he stumbles upon a young pegasus in need of help. Harry, being the kind - hearted person he is, bonds with the pegasus and it becomes his familiar.
Perhaps it is given to him by a mysterious figure. This figure could recognize Harry's potential and believe that he is the right person to wield the trident. The figure might be from a different magical culture that has a connection to the trident and sees Harry as a key to some greater purpose.
He would probably become extremely powerful. He could use the Infinity Stones' powers to defeat Voldemort in an instant. For example, the Power Stone could enhance his magic to an unimaginable level, and the Time Stone might allow him to go back and prevent bad things from happening in the wizarding world.
He might find it in a hidden chamber in Hogwarts. There could be a series of magical puzzles and traps that he has to overcome to get to it.
He could get them from his Muggle relatives. Since he spends time with the Dursleys, there might be a situation where he stumbles upon some of their tools or weapons, like a gardening hoe that he could potentially use as a weapon in a fight. Another way is through his Muggle - born friends at Hogwarts. They might bring in some items from the Muggle world that Harry then takes an interest in and decides to use.
He might inherit some of the cars. For example, he could inherit a classic wizarding car from his parents' old friends. Another way could be that he wins them in magical contests. There could be a Triwizard Tournament - like event where the prize is a unique and powerful car.
Maybe it was given to him by a mysterious stranger. This stranger could be someone who has been observing Harry from afar and believes that he is the only one who can handle the power of the hand cannon. The stranger appears out of nowhere, hands it to Harry, and then disappears again without a trace.