That's actually quite logical when you think about it. Such "palace guard" foreign mercenaries were invariably very well paid for obvious reasons and tended to enjoy all kinds of special privileges, often including a virtual immunity to legal repercussions for pretty much anything short of murder (and sometimes even that). The operative logic is simple enough: foreigners in a strange land far from home, and more or less resented by the natives for any excesses they may have indulged in under the protection afforded by the patronage of the biggest shot around, their continued prosperity and survival is pretty much directly linked to their employer remaining on the throne. They themselves are unlikely to try a palace coup, as there would be no way for them to keep the power if they were succesful - indeed, if the protection of the ruler was removed for any reason, they would more likely than not be summarily massacred by the angry natives. Even if their relations with their hosts weren't that bad, their claim to legitimacy would be a round zero making keeping the seized throne a very losing proposition.

And more importantly, being foreigners, they had no prior local looyalties based on family, political party, clan membership, client-patron relationships etc. etc. as any natives otherwise eligible for the job nigh invariably did. You brought the outsiders to do the job just because they were outsiders unconnected to the festering pit of intrigue that was the court, whereas if you employed natives for the job there would be an extremely real risk of one of them one day shoving a sword in your back so Uncle Mikaelos can become the next boss and reward them handsomely for the lift...

The Praetorians are a brilliant example of that sort of trouble, having at least once flatly auctioned the Roman Empire to the highest bidder. Not really surprising they were eventually disbanded and replaced by personal hired guard corps usually of the model described in the first paragraph (eg. the German guardsmen of many of the later Emperors). Similarly pretty much every single new Byzantine Emperor formed his own new guard unit, although they apparently usually just relegated the earlier ones to less exalted (and risky) duties.