Year 0. A great Empire, powerful due to its control over magic, collapses. A rival empire takes over their territory and scatters its people. They seek to destroy its capital and salt the ruins, but its armies hold them back long enough for an evacuation of the people and magical artifacts in the city to take place. Some of the greatest minds and most skilled mages of the world have now become refugees.
They are protected by a kingdom, A. A gives them land and refuge on the conditions that they train its people and soldiers in magic and lend it their mages in their wars.
Year ~200. The mages' city is one of the jewels of Kingdom A. It is located in the highlands, and is well protected both by the geography, its soldiers and its skilled mages. People from all over A come to be trained in magic, but they are then required to serve their duty to the city. Most of this duty is used up in helping Kingdom A in its wars. But slowly, they are being less and less compliant to the wishes of A...
Year ~400. In a period of massive civil war in A, city A breaks from their bondage. They no longer help the new regime (except as paid mercenaries), technically still being its vassal but only in name. They are well-known and powerful, and it would be too annoying and costly to attack them, which will also cut A off from their services. By now,A has mostly subdued their local enemies and the only threats are other civilizations, which the mages do protect them from. But they do not bow to their whims or send them any help to deal with local rebellions or anything of the sort.
My question is, what kept these mages from shirking their side of the deal immediately? Or at least, as soon as they had their city?
Context: In this setting, anybody can learn magic, but everyone has a different capacity. In general though, skill beats talent, and almost all magic happens through devices (that require a magic-trained practitioner). Most of the know-how to build and use these devices is held by the mages, though some of the most common ones can be built by skilled craftsmen all over A (through overuse, the knowledge has percolated throughout society).
The city of mages works as a kind of "university", and they have opened universities elsewhere in A too. But they also have their own population, city guard and so on. Certain knowledge and most magic tools are only given to their own citizens, either through birth or oath.
One possible way, I think, is through siege. It is hard to take over this city, but possible to cut off its supplies. It is hard to build magic weapons without magic metal, and everyone needs food. But I don't think that's a strong enough reason, and using this as a reason precludes them from EVER being free.