Let's say, for example, someone wants to use the restroom at a gas station here in the US. The door is closed. It's more polite to gently rap on the door, or ask "anybody in there?" before trying to open it. If no one answers, he can try the door. If it's locked, someone's probably inside and just didn't respond to the knock, or you might need to get a key from the attendant. If it opens, it should be empty; not many people will let someone interrupt them on the toilet instead of locking the door or at least saying "it's occupied".
So how can it be rude to knock on the door? In my opinion, it's only rude if they knock loudly, or if they knock every minute until you're finished or something. The urgent knocking described in the OP might fit that description.
On a side note, I was on a flight recently, and there was mild turbulence while I was in the restroom. The attendant knocked on the door and asked me to return to my seat. I hadn't started, so I returned. A few minutes later, the turbulence died down, and I re entered the toilet. But once again it started up, and the attendant knocked on the door. This time I decided not to leave, and she kept on knocking and knocking. I finished, and when I left she chewed me out for not returning to my seat immediately. Tough.
I may have missed the point here, but I don't see that this has anything to do with gender or mixed bathroom facilities.
Banging urgently on a toilet door in a public place is unforgiveably rude behaviour in any circumstances, regardless of whether men or women are involved. In my view, it would also be unacceptable for a man to do this if there were a man inside. If the door has been locked for an excessive amount of time, then it might be acceptable to tap politely and say something like, 'Hello? Are you OK in there?', or 'Excuse me, will you be much longer?'.
The gender issue seems to be beside the point - this is just a question of basic human respect. Or lack of it.
I guess it would be helpful to understand what a public shared restroom would be. In the U.S. many businesses have separate bathrooms for men and women. In larger businesses and places like stadiums, there would be many private stalls in each of these. So I am not sure if a ¨public shared bathroom¨ means the ones with many stalls.
Smaller businesses might have one small bathroom with a door that should lock (although occasionally the locks may not function), that can be used by either men or women. It is common that it is difficult to discern whether someone is ocupying the restroom or not and it is a common courtesy to knock once and wait and see if you hear anything before trying the handle.
Knocking repeatedly in a demanding manner would generally be considered rude whether done by a man or a woman.
However, I think there can be exceptions. It is also considered rude to spend a very long time occupying the bathroom if it is the only one.
I once waited for a VERY long time (more than 10 minutes) for one of these shared bathrooms in a restaurant while I kept hearing a man inside holding a conversation (that I could not hear the details of). I tried to give him the benefit of the doubt that perhaps he had other family members in there with him that he was trying to help, but finally I gave a couple of sharp knocks on the door to make my point that someone was waiting to use the restroom. When he came out alone, I am sure I gave him a fairly critical look because I honestly suspect that he was just rudely using the bathroom to obtain a place to have a more private conversation on his cell phone instead of using the bathroom only for his physical needs.