It got frozen by Ice Beam, then it thawed out and used Thunder Wave. I thought only Sacred Fire stuff can do it. Can anybody help?
Frozen:
Effect: >Freezing causes a Pokémon to be unable to make a move for an indeterminate number of moves. The specifics vary between generations.
Further,
From Generation II onward, freeze has a random, 20% chance to be cured on its own on the frozen Pokémon's turn. Consequently, the frozen Pokémon may thaw out on the turn of freezing.
Source
There it is! A simple matter of probability and chance, and you were caught on the better end of the deal. Good for you, you lucky person! Now go wish for a trip to Disney or a Shiny before your luck runs out!