Each NPC has their own needs and wants. So long as those are met they will not move to another settlement. Players have more influence than the NPCs on how this would work, notably players that have the power to control taxes, land usage, etc (Land owners, Mayors, Counts, etc). If NPCs were in control of said resources, they would self regulate to become a more stable settlement based on their AI needs and wants. If they were unable to regulate, the settlement would likely decline to a lower settlement type until it was able to be regulated by either the managing player(s) or NPC(s).
For instance if a settlement is lacking food and more sustainable farms are created with plots of land granted by the Count for this purpose, the settlement should stabilize more. Another option might be to trade with neighboring settlements.
If there were bandits hijacking traders the settlement , sending a hunting party out to take care of said bandits would ease the tension of the local citizens and they would be more likely to stick around.