Its a bug...have the same issue. Hopefully it will be fixed with a future patch
A dumb question but how do you know the bed count is dropping to zero after you leave? The only way I have found to check total status is to be at the work bench of the Settelment I am checking on. being that I am going on 6 Settelments that is a lot of running around just to keep them all in order.
Open "Data" go through the tabs until you hit "Workshops"
I'm guessing it's a bug in the Pip-Boy display, not your actual settlements having an issue with lost beds....
I've had this bug pop-up as well. Sanctuary keeps dropping it's defense, beds and etc to zero in the pip-boy when I'm traveling, but it fixes itself when I go there.