I tried to think of how lighting works.
Then it struck me!
Okay, listen up, buttercup. The joke is that the person was trying to figure out how lighting works, and then they had a sudden realization, which they describe as "it struck me." The humor comes from the double meaning of "struck," as in both having a thought and being hit by lightning. Get it? You probably don't.