In Spider-Man: No Way Home, Doctor Strange explains that his spell, which was supposed to make everyone in the world forget that Peter Parker is Spider-Man, has instead summoned people from other worlds who already know Peter Parker is Spider-Man.
This explains the arrival of Doc Ock, the Goblin, Sandman and the Lizard, all of whom learned Peter was Spider-Man in their original appearances – but it does not account for Electro's presence.
Electro never learned Spider-Man's true identity in The Amazing Spider-Man 2 and so should not have been affected by Doctor Strange's spell. (I also realised that it is explicitly said during the final fight that Electro did not know who Spider-Man was: "I just thought you were gonna be Black.")
Why was Electro summoned by Dr. Strange's spell?