From a purely syntactical analysis, it could be both.
The only thing that can tell us which is the better fit is semantics. In the example you give, even semantics do not make it clear:
- Major cities are likely to thrive if they receive the necessary financial support;
- Governments who spend the right amount of money on (making) the major cities (thrive) are more likely to be popular governments and thus be reelected—which I would say is a pretty good definition for ‘thrive’ as applied to a government.
I would consider it more likely that the cities are what’s being talked about, but the other option cannot be ruled out without more context.
If the major cities receiving financial support were to be swapped with something else, this interpretation could swing the other way:
Governments must ensure that their core constituents feel they get the political support they need in order to thrive.
In this case, it is almost unambiguously the government that is thriving (to me, at least), since political support is rarely something an individual person needs in order to thrive.
If you want to avoid ambiguity entirely, I would simply phrase the sentence in a different way altogether, for example:
In order to ensure that major cities thrive, governments must ensure that they receive the financial support they need.
(This is of course also a bit ambiguous technically, since ‘they’ can still refer back to the governments, rather than the cities—but that would make for a very odd sentence with a lot of semantic jumps. There is at least far less risk of ambiguity in this version.)