They already explained this in the anime thousand of times, one of the best time is in this episode --> https://www.youtube.com/watch?v=bax7ydFbiZU
Go to 18:30, episode: "There is a crowd". Brock will explain why Electric type moves aren't very effective against Grass type Pokemon and have no effect on Ground type Pokemon, and how they work normally on Ground Pokemon who are in the air like in the Battle against Roxanne, when Pikachu's Thunder worked normally on Roxanne's Geodude.
Resume: Electric moves are weak against Grass type Pokemon and have no effect in Ground Pokemon, because the electricity flows through the body of the Pokemon and disperse in the ground, tree, wall, etc. Like really happens with trees in the real world. That is why is Electric type moves aren't very effective against Grass type Pokemon and have no effect on Ground type Pokemon. However, Electric type moves work normal if the Grass type and Ground type Pokemon are not in contact with the ground or are soaked with water. The anime never made any mistake about the logic, people just don't pay too much attention to the details.