Okay so I misspoke. I don't want anyone to see I'm using the commode. That's why the door is closed. I've lived places where the bathroom door is open most of the time, so just closing it is sufficient. I've lived places where it's closed all the time (e.g. pets) so it gets locked.
At this point I have to believe you're either a troll or some sort of GPT-3 bot based on how you're almost trying to miss the point and - seemingly intentionally - misconstrue very easy to understand and generally accepted concepts.
Door is not the only way to solve this issue.
The question can be asked, why would someone walk in if they can see you using the commode ?