Any Pokemon that you caught yourself on your own game will always obey you, no matter what level they are.
However any traded Pokemon will only obey if you have the right gym badge. With each alternate badge, higher level Pokemon will obey, e.g. up to level 30, up to level 50 and so on. This is explained pretty clearly in the game. Once they are higher than your badge level, they will randomly disobey, ignore your commands, use different moves and so on.
A traded Pokemon is any one that comes from a different game, even if you own it yourself and trained the Pokemon on the other game. Think about it - how is your game supposed to know that you own the other game?!