Sounds like a glitch. It could just be one you couldn't prevent, or it could be cause by hacking your Pokemon or game. I know this happens sometimes, but there is really nothing you can do about it other than shutting it off and hoping it doesn't happen again.
EDIT: I think Xtreme is right, it sounds like a known glitch, the Fainted Pokemon glitch. Harmless, the only way to stop it is to reset the game.