Yes, you can advertise to only one sex. The problem is they advertised a job ad.
Also some recruiter are explicitely trying to correct a gender imbalance and are therefore actively seeking female candidates. Does that become unethical to advertise to women?
Um, the cleaner is usually coming in when the locker room is empty so sex doesn't matter.