I had to register for this site for the sole purpose of commenting on this thread, outdated though it may be.
Let me begin by saying that it is always a good idea to knock when entering a bathroom that is likely to be occupied, particularly in unfamiliar territory, and particularly when the opposite sex might be involved in some way.
That being said, I am pleased to see that a clear majority have correctly voted that person A is at fault.
In fact, person A is so clearly and unequivocally at fault that I find it appalling that almost half of the people voted for person B.
It should not have to be convention to knock on a closed bathroom door. In my experience, the bathroom door being closed still only signifies a low probability that it is occupied.
When I use a bathroom, I have the full understanding that it is my responsibility to ensure my own privacy. My privacy is thus only dependent on the actions of one person-- myself. By not locking the door, I place the burden of my privacy in the hands of the rest of the universe. This is not their burden to shoulder. The only person responsible for my privacy is me and that is absolutely all there is to it.
Before I get trolled let me clarify. My responsibility to others who may be using a restroom that I attempt to enter is not to DELIBERATELY enter an occupied restroom. As long as I truly did not intentionally walk in on someone, I am blameless.
So if the following conditions are satisfied:
1. The door has a functional lock that is not confusing or difficult to use
2. I have no knowledge that the bathroom is occupied
3. I accidentally walk in
Then it is the person who failed to lock the door who is at fault, just as it would be my own fault if I had failed to lock the door when I used the same bathroom.
I am one person. One person is all it takes to secure one person's privacy. Asking the rest of the world to knock is asking any and all potential "intruders" to secure your privacy because you failed to secure it for yourself, when doing so was incredibly easy in the first place.
If you are at a social gathering with 10 or more people, you can be sure that some of them will be knockers and some of them will be knob checkers. In that sense, this isn't an issue of person A vs person B, it's person A vs person B, C, D, E, F, G, H, I, and J. Do you really want all of those people to be expected to take an action that need not be taken if you simply lock the door in the first place? When you lock the door, it doesn't matter how many are the former and how many are the latter. Either way, everything is taken care of, no embarrassment need occur. This is all to say nothing of how annoying it is to have to verbally respond to people who knock on the door when you are in the bathroom. Just check the lock and everything is handled with no superfluous knocking or awkward conversation--- the kind of conversation I really don't want to have while I'm handling that sort of business.
If you are person A, you are empirically, inarguably, and unmistakably at fault for not locking the door. This is black and white. No gray area exists. If you go through your life not locking the door to the bathroom, you will go through life being walked in on, creating awkward situation after awkward situation for you and your array of unwitting "intruders."
Again, trying not to be too terribly redundant, knocking is generally a good thing to do, but it is going above and beyond the call. If you think that person B is at fault, there is a basic element of personal responsibility concerning etiquette that you just flat out don't understand. Take this opportunity to learn because your position is unjustified to the point of absurdity.