It sort of depends on how sound proof the door is. Most bathrooms I've seen that have a fully closing door (not a stall), you have to shout to be heard through the door anyway. So I personally find it vaguely annoying when people knock, because then I have to shout "JUST A MOMENT" while on the toilet, which is just rather uncomfortable. If they just try the door, then they get to realize on their own that someone is in there without requiring any interaction from me.
But here's the thing - even though I find the knocking slightly uncomfortable, I recognize that not everyone thinks about it the same way, so I don't see any value in getting upset about it. There's not a 'right' way or a 'wrong' way to handle it. My preferred way doesn't appear to be your preferred way.
I certainly wouldn't *lecture* other grown adults about how they approach the bathroom door, and if someone (even my superior) lectured me, I'd be pretty annoyed. If someone who was not my superior lectured me about how I approached a bathroom door, I'd be floored.