I keep running into the same issue when it comes to certain trainer battles, I've had to constantly save before hand and then soft reset to fix it. It's random and there's no avoiding it until the bug is fixed.
im pretty sure its based off some status effects like dodging moves or flinching if the opponent cant take their next turn the game bugs out