What might be happening is some of the villagers register their bed in another cell, one other than the one their in. You can check if this is the case by looking at the unsleeping villager, and typing /data get enity [entity id, you will see it, just tab to it]. It should be right at the top, labeled "minecraft:home". I had the same issue. You can prevent this by putting in the beds once you put the villagers in the cell.
What might be happening is some of the villagers register their bed in another cell, one other than the one their in. You can check if this is the case by looking at the unsleeping villager, and typing /data get enity [entity id, you will see it, just tab to it]. It should be right at the top, labeled "minecraft:home". I had the same issue. You can prevent this by putting in the beds once you put the villagers in the cell.