This question is quite old. But seeing that it has no selected answer, I thought I'd help by giving a rational explanation even from the game's point of view.
Pikachu's electric attacks have no effect on any ground type Pokemon. However, there are certain attacks that change the type of the opposing Pokemon. This includes Soak - a move that changes the opponent's type to the water type.
We can assume that Pikachu used the move soak in a variation when it set off the sprinkler system because of the fire. This also explains why it took only a few thundershocks to take out Onix, which has respectable special defence in the early game.
Hope I helped you gamers!