In some cases, a job can be offered to someone of a particular sex, because of what is called a 'genuine occupational qualification'. Examples could include:
some jobs in single-sex schools
jobs in some welfare services
acting jobs that need a man or a woman