There are times........
When it's needed to be able to hire a specific sex.
Washroom attendants aren't as common these days, but there are similar posts such as an attendant in a locker room at a spa/public pool/school where it would be very awkward and creepy to have a male supervisor in a female locker room or a female supervisor in a male locker room. It's worse when it's a school and we're talking about under 18's. This is an easy case.
A harder case example is when a male owner of a photography company wants to start making school photos, children's sports photos, etc. There is a huge bias against a man working with kids, but a female photographer or assistant has no such automatic bias and can pose the kids, brush their hair or straighten their coat. It's a lucrative business so it's not just weirdo guys that want to get into it. (It's really good money, actually, but a lot of work). If the male company owner advertises for a female assistant, is it discrimination?
A doctor may want a nurse/assistant that is the opposite sex to assist patients and to be present to avoid lawsuits. This can be especially the case for gynecologists.
I'm sure that if I thought about it some more I could come up with other situations. One last one that I remember vividly was during the set up of a concert with union labor. The Union always calls up workers based on seniority and doesn't take into account how strenuous the job might be. An old guy couldn't hold his end of a really heavy speaker and dropped it on a coworkers hand. The job needed a bunch of young bucks rather than the wisdom of long experience. I worked on one more job with that Union and ran before I was injured.
Real discrimination comes when a job can be done (physically, mentally, politically) by any number of people but the opportunity is only offered to a select few based on artificial criteria. I'm past the age and health where I would be worth my salt as a basic roadie on a tour so I shouldn't be considered and part of that would be age related. If there were also the need for an electronics tech or another post where brains were used more than brawn, I should be given a chance at it.
It's tough to draft a set of laws that can apply to every single situation. Details do matter.