I've noticed that the position of villager in relation to the workstation is key. The villager must be standing on ground level next to the workstation.
Bear in mind that villagers can't pathfind across anything, no matter if it is non-solid. Place a torch in front of a villager and the villager will try to pathfind around it, not through it. Only exception is open fence gates. Other non-solid blocks will block a villaer from pathfinding. Whenever a villager loses its path, it might choose to disconnect from workstation.
This includes if the villager is standing on a bed. The villager can't seem to find its workstation if it is standing on a bed.
So, you need to make sure that the villager is standing next to the workstation, not standing on a bed, not blocked by anything at all whatsoever.
Bear in mind also the villager has to sleep, otherwise it may also disconnect.
Add to this that the villager will search for the foot end of the bed, and will get out of bed in the foot end. Blocking the foot end may cause the villager to get confused and disconnect.
The only guaranteed working design I've found is to place the villager in a 1 X 4 box, that is occupied by Bed (head end), Bed (foot end), Place to stand, and finally Workstation. This will keep the villager occupied and happy.
3