How AI hires mercs may depend only on their monthly balance (you can actually see it in diplomacy view), which means accumulated money may be irrelevant. Though I do not know this, possibly both factors are taken into account. To me it looked like AI did not hire big stacks unless it was a really big nation.The lowest good (after hiring mercs) among my opponents was 961. At 20 per month for a huge stack, that’s 48 months in the bank. Presuming they had positive income before that (because how else would they get that much cash), they can likely support them far longer.
I do not normally hire mercs because I like Military Traditions. At my current point in the game, each merc unit costs 8.5 ME to hire and then decreases ME income. Presuming that every 10 merc units I hire costs me a Tradition is probably an underestimate, but I think it makes it clear why I don’t hire them routinely.
Lastly, yes, mercs will unflag on friendly territory occupied by the enemy. I watched 6 separate merc units do so one at a time.
What was meant as a short victorious war turned into a bit of a meat grinder, but I eventually won in part because the AI decided to try to replenish a huge stack of troops in the mountains while eating massive attrition.
I see you are role playing and avoid mercs due to ME. I do not care much about ME because mercs are very cheap, do the job and AI is not getting them because they fight on my side.