you just need to talk to your villagers regularly. they may tell you a rumour about a villager who might be thinking of moving away or the villager themselves may ping you and tell you that they're thinking of moving. just tell them that you want them to stay and they won't move.
By talking to villagers(they'll give out a hint that sucha such is moving)
Sometimes it's unexpected and no one says anything
To get him back, you have to go through the 16 villager cycle