It's possible that he stumbles upon this ability during a Defense Against the Dark Arts class. They might be learning about different forms of magic related to the elements, and while practicing some spells, he somehow taps into the power to control lightning. This could be a shock to both him and his classmates, as well as the teacher.
Maybe he discovers it during a particularly intense storm at Hogwarts. He could be in a dangerous situation, like being chased by some dark creatures, and in a moment of desperation, he unknowingly summons lightning to protect himself.
Perhaps it has something to do with his family heritage. The Potter family might have some long - forgotten connection to an ancient magic related to lightning. As Harry delves deeper into his family's history, he uncovers this latent ability and starts to learn how to control it. It could be a gradual process, starting with small flashes of lightning and eventually leading to full - on control.
In some fanfictions, it could be during a moment of extreme danger or intense emotion. For example, he might be facing a powerful dark wizard and in a desperate attempt to defend himself, he unknowingly channels lightning. It could also be through some kind of ancient magic that he stumbles upon, perhaps while exploring a hidden part of Hogwarts. Another possibility is that it is a latent ability that is awakened by a powerful magical artifact that he comes into contact with.
One challenge could be controlling the intensity. Lightning is a very powerful force, and it might be difficult for Harry to rein it in. He could accidentally cause too much destruction when he just wants to create a small spark.
Another way could be as a result of a special encounter. Maybe he discovers a hidden scroll or a mysterious artifact that imparts the power of lightning control to him. This discovery could be accidental, like when he's exploring an ancient ruin or during a battle when he stumbles upon something unexpected.
One challenge could be controlling the intensity. Lightning is extremely powerful, and if he doesn't have proper control, he might end up causing more harm than good. Another might be the unpredictability of the element itself. Lightning doesn't always behave as expected in nature, and it could be even more difficult to manage magically. Also, he may face opposition from those who fear his power or think he's becoming too powerful.
Maybe he accidentally finds out when he is near some magnetic objects in Hogwarts. For example, he might notice that he can make the metal keys move towards him without using magic spells he already knew. It could be during a time when he is exploring an old, forgotten part of the castle where there are a lot of metal objects and strange magnetic fields.
In some fanfictions, it could be through an accidental encounter. Maybe he was in a situation where metal objects started to react to him unexpectedly, like when he was near a bunch of keys and they suddenly started to move towards him. This made him realize that he had this strange new power.
Perhaps he has a strange dream where he's in a world made entirely of shadows and he can manipulate them freely. When he wakes up, he starts to experiment and finds out that he can actually do the same in the real world. He might start with small things like making the shadow of a quill move on his desk, and gradually discovers the full extent of his power.
Perhaps it's through an accidental encounter with a powerful magical plant. He tries to interact with it in a normal way but ends up influencing its growth and behavior. This unexpected event makes him aware of his unique power to control nature. For example, he might touch a withering plant and suddenly it springs back to life and starts to grow rapidly under his touch.
Maybe it has something to do with Harry's exploration of his own heritage. As he delves deeper into the history of Gryffindor and his own family's connection to the founder. He comes across an old spell or an enchanted object that, when he touches it, he feels a strange power flowing through him. This power then manifests as the ability to control the flame of Gryffindor.
In some fanfictions, it could be through intense magical training and study. Maybe he discovers an ancient spell or a hidden magical technique that allows him to assert control over the dangerous Fiendfire.