Ghosts hate light, and electricity creates light, which causes ghosts to vanish.
If anybody has a logical answer to this question, don't hesitate to answer.
Electricity is used to creat light. I am a science fan so I'll say it. Electricity is used to generate heat in tungsten and it glows then light is produced. But electric moves just shock the opponent. Even if you say thunder is lightning, ghost don't look at it. This my theory.
Hope I helped!