Allowing legitimate discrimination based not only on safety but the need for privacy and dignity is not comparative to the examples that you have used. The legitimate discrimination of excluding all male people (over the age of a child who requires care if it is appropriate for that child to be there) from a female single sex space is not marginalising a 'whole community'.
Legitimate discrimination based on a person's sexed body is based on safeguarding principles where a pattern within the population has been identified and evidenced over time. Hence, much of the world has sex segregated single sex spaces. Based on sex. Not on gender.
However, it is important for specificity that a country regulates their discrimination laws based on their own country's requirements. Therefore, your attempt at leveraging a war in another country into a country's discrimination law is irrelevant and highly inappropriate.
Also, the basis of assessing whether a specific group of people is at a population level for that group not an individual level. This makes your example of nannies also irrelevant. When considered as a group, it is not likely to be evidenced that a nanny will have a higher propensity to murder than other people of their sex. Therefore, collectively it would be inappropriate to exclude nannies from services open to female people.
You have again tried to use what you obviously think are great 'gotchas' to support your view and they continue to fail. Because they are either incorrect or they are irrelevant. Your comparators are false. A male person has not changed sex category, therefore they should always be treated as a male person. If they are vulnerable, they should be treated as a vulnerable male person.
Excluding ALL male people (above the age of a child if it is appropriate for the child to be in the space) from a service or a space meant for female people is a legitimate discrimination based on historic and ongoing patterns of male behaviour.
If you wish to change this ability to discriminate in a particular country, you would need to show through long term statistics and studies that the group of male people have the same or lower risk of committing a violent act or a sex crime as the general female population in that country.