Avengers: Endgame was the culmination of more than 10 years and more than 20 movies of ongoing story. What made the Marvel Cinematic Universe so unique was the way that it brought comic book style continuity to the big screen. The MCU has rules that tend to be important from one movie to the next. Of course, sometimes, rules are made to be broken.
There's a lot of detail to juggle in Avengers: Endgame with so many characters running around, but the team behind the big MCU finale admit they didn't let those details get in the way of telling an awesome story. Writer Chritopher Markus admits to Slashfilm that Endgame played a little fast and loose with the way that Thor's hammer worked because the sequence was just too cool not to include. According to Markus...
There was certainly a debate at one point because particularly in Ragnarok, it establishes that Thor can summon the lightning without the hammer. I think Odin even says, ‘It was never the hammer.’ And yet Cap summons the lightning with the hammer. You get to those things and you’re like, ‘It’s too awesome not to do it! We’ll talk about it later.’
Our understanding from the first time we meet Thor in his first solo picture, is that Mjolnir the hammer is the place where Thor draws his power. Without the weapon, he isn't really the God of Thunder because his ability to summon lightning actually comes from the hammer.
However, in Thor: Ragnarok Thor discovers that the power is actually part of him, and that he can summon it all at will. The hammer acted only as a focus that helped him control and harness the power, when it is destroyed in that film, Thor's power ends up going wild.
And so, if the power to summon lightning is part of Thor, and not the hammer, then Captain America shouldn't technically be able to summon the power simply because he's capable of wielding the weapon.
In the end, the decision was made to simply let it go, and to be honest, i didn't hear anybody complaining about the apparent continuity problem. The sequence where Captain America holds Mjolnir was one of the most popular among fans and it was only made more fun by the lightning.
It's not like they can't write in an explanation for the lightning if they really want to. We know that somebody else is going to be using Mjolnir before too long. Jane Foster is set to become The Mighty Thor in Thor: Love and Thunder. Unless she has no lightning powers at all, it would seem that perhaps Mjolnir is capable of bestowing such an ability, even if Thor happened to be able to do it anyway.
And even if no explanation is forthcoming, who cares? It was awesome.