This bug was largely fixed in 20w19a, though not entirely. I tested this on a plains superflat world. Every villager went to and slept in an empty bed, except for one. He occasionally would go from one occupied bed to another, though he never went to the only vacant bed in the village. My assumption is that this occurred because the bed was quite far away, meaning the detection range for beds is still insufficient.
To reproduce, go to a village that is sufficiently large in area, most easily found in superflat worlds, and when it is time for the villagers to go to sleep, see if any of the villagers don't go to an empty bed. If you can't find this on your own, simply add a bed on one side of a village, and add a villager on the other side. If they are far enough away from each other, you should see the bug in action.
Linked issues
Attachments
Comments 3
This report is most likely a duplicate of MC-197857, since this is a more active and updated ticket.
Forward-resolving to MC-197857.
If the bed is > 48 blocks from that Villager, then this is WAI. Villagers can only know about things so far away from them. They go from home to home at night because that is what they deem as the safest thing to do, they are not actually trying to sleep in occupied beds.