Villagers are actually not meant to disappear randomly in game. Many of these cases had been result of some bugs and glitches.
Most cases of villagers disappearing was a result of bugs in 1.16 and 1.17 versions. There are still cases of villages disappearing when they are too close near the chunk borders. The earlier versions of Minecraft had reported bugs which caused villagers to merge into when they got near each other.
Other ways you could lose your villagers to are the mobs. Make sure that have proper roof, food and iron golems when they work around, And do not forget to link them to beds so they don’t wander away as soon as you get them to your base.
Due to the bugs and glitches villagers, as well as the others mobs still have chance of randomly de-spawning, even if it is quite rare these days.
Will Villagers De-spawn In Boats in Minecraft?
No. Instead boats are the best way to pull the villagers back to your base and can be used to repopulate the whole village. Try to get your villagers to sleep them in beds, protection and food for breeding.
How Do You Keep Villager From De-spawning?
As said before, providing them with enough unclaimed beds and food will make them stay in the village and not wander away.
Do All Villagers Need Beds?
Players may line up villagers in in queues for trading items instead of having them live around the village. Hence to hold them in small cubicles won’t necessarily require to have beds around them, although before placing them in the cubicles you will need to have them claim one bed to claim them as part of your villages and to breed them to make more.
Which Mobs Hate Villagers?
Pillagers, Zombies, Illagers kill villagers in Minecraft. Villagers are particularly safe from zombie attacks during nights if they have claimed beds. Iron Golems also keep patrol the village and kill any hostile mobs that threaten them.
Pillagers mostly attack villagers during raids. Protecting the village by walls and having iron golems around helps defending the villagers too after they run into their houses. These Pillager raids take place in Normal and Hard mode.