In a battle I just had I selected to switch out my pokemon. My opponent used Hidden Power and it killed the pokemon I was switching out, then it automatically switched into the pokemon I wanted to switch to.
The foe's Blaziken used Hidden Power! I should have switched to Munchlax here...