Actually, if you were to implement something that monitors the state of the door lock, the same hardware could run an OCCUPIED/VACANT LED on the door itself to avoid the awkward door knock in the event that the door is closed while the bathroom is unoccupied.
Of course, if someone forgets to lock the door, that's basically an invitation for everyone else to walk in on them. On second thought, it seems to me that the best solution here is to mount webcams in the bathroom so that anyone can see if it's occupied. Seems like the only foolproof way to go here.
On a related note, we have a take home fridge at ATK, there was some discussion about how to tell when new food was added to the fridge. Cameras might have been an option there.
Of course, if someone forgets to lock the door, that's basically an invitation for everyone else to walk in on them. On second thought, it seems to me that the best solution here is to mount webcams in the bathroom so that anyone can see if it's occupied. Seems like the only foolproof way to go here.