When your pokemon gets to a high enough level compared to your gym badges, they stop listening to you. They completely stop using attacks and whatever. This makes them pretty much useless, which I think is quite dumb. What I suggest, is to add a level cap for them instead. It should work like the trainer level cap where you can't get any more XP unless you beat the next gym. This makes it so your pokemon can't get to a too high level and it doesn't become useless. I always end up getting my pokemon to a too high level before I can beat the next gym, which means I can't even use him to beat the gym and I'm left with my most powerful pokemon out of the fight.