In my experience, the decision to close the lavatory by the cockpit door is entirely up to the discretion of the captain. Just like the decision as to whether or not to turn on "channel 9".
It has been rare, on my flights, for this lavatory to be closed.