>>40978184In early lore, they mentioned that wild Pokemon were jealous of captured Pokemon - which is one of the reasons they'll attack you; to prove they're superior. So, I think they could just adjust that to take your Pokemon's level into account, that way if your highest level Pokemon in your party is only level 20, a wild level 40 won't attack you because it knows your not even a challenge to it. It'd probably be a range within a few levels.
Now, you still have a few problems, like the Gym Leaders or whatever villain group your trying to take down, but there are a few easy solutions to this too. For the Gym Leaders, it's been implied, and even shown off in Pokemon Origins, that Gym Leaders have multiple teams on the ready, to fight trainers of varying strengths; so the team they fight you with would depend on how many badges you already had. As for the villains and even your rival, you could story-beats that only occur after you do specific tasks which are reliant on how many badges you have - where, after you leave the town where you get your 4th badge, your rival will always approach you after you leave that town (or whatever town you leave next, if you fly to another one right after) or you're alerted to something the evil team is doing, and some story reason has you go to wherever they are to intervene.
The only real problem would be other trainer battles, but it could be adjusted similar to how I mentioned Wild Pokemon would work, where people can just tell how strong you are. Only people who are weaker will approach you at first, trying to show their strength off, but as you get more badges, stronger trainers will approach you to - And just so it fits with Pokemon lore, you can still talk to the stronger NPC trainers and try to initiate a fight, and after giving you a prompt to back down, you can attempt to fight someone way out of your league - and maybe if you somehow win, you'll get more money or something for winning.