This is true only for irrational discrimination. If you simply hate women, but women are equally productive to men, then you will lose out on getting good women. I.e., you might choose a man of quality Q-d over a woman of quality Q simply because you dislike women.
But in this case, the discrimination is rational. Due to maternity leave, a woman of equal skill creates significant cash flow risks - if she takes leave, you either go for 3 years with her job not getting done, or else you hire a replacement and risk being stuck with unnecessary employees in 3 years.