There are 3 possible reasons:
1. sleep activated on the turn you switched, yet didn't show it/you didn't see it
2. the yawn on Kangaskhan was still active in the switch
3. it was a glitch
I don't know enough about yawn to add more, so I have posted a link below to the move.