The legitimate aim: To ensure that no man can say "I wasn't flashing, I was just getting changed."
The proportionate means: Some trans identified men feel invalidated. Some trans identified men are subject to transphobia in male toilet facilities.
Men take advantage of plausible deniability to sexually assault women all the time. Women don't report it for fear of not being believed. Or worse, if "trans" is involved not just not being believed but being DARVO'd into being the transohobic, bigoted aggressor. It being accepted that penises are not allowed in women's toilets and changing rooms will stop the everyday "did he really just assault me?" from being in our private sex segregated spaces.
Do add your own legitimate aims and proportionate means!