Yes, so you have a lock on the door that you can only manipulate from your room. Unlock it when you need to use the bathroom, lock it otherwise.
This of course doesn't allow you to lock the bathroom when you're in it from other people also in your hotel room. Although this is certainly much less of a concern.