There is a strong culture for leaving the door open, to avoid the awkward door knock. This defiantly does mean we can have false "occupied" states, but in practice at our office this doesn't happen.
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.
What would be ideal is if it could be wired to the locking mechanism of the door. That's probably decently simple to do if the door is locked using a deadbolt because something physical is actually entering the doorframe. If it's just a lock that prevents the doorknob from turning, then you'd likely need to disassemble the locking mechanism and see where you can attach a switch.