If that is the case, obviously we discriminate by it, because we try to choose people who are better at X when trying to find people for X. Tether there is a single underlying characteristic that makes you better at X (a pre-determined IQ) that is discriminated for is perhaps harder to know. I certainly don't think that school for example advances students based purely on intelligence - discipline, even obedience, like-ability, sometimes teamwork, are all at least as important to what makes most good students successful.
Related to 2,my answer is very simple: companies don't take the full burden, at least in most countries. In general, there is a shared burden - the employee has reduced pay, the state is paying for some or most of that, and the company is forced to keep the position open for the employee when they decide to return. In my country at least, they are also free to hire a temp to fill that position for the 1 or 2 years of maternal leave.
I think about this often, so let me try to play the devil’s advocate: (1) why are we (the society) allowed (even encouraged) to discriminate for intelligence at almost every point in our lives (school, job, marriage)? (2) sure, companies are forbidden from discriminating because of certain characteristics, let’s take pregnancy; but why should companies be expected to shoulder that burden all by themselves? It’s more than reasonable for the society to cover the costs, as a sort of insurance policy - it probably doesn’t matter that much for big companies that can just statistically assume that a certain percentage of employees will be sick / pregnant / etc. but for a small company 1 missing employee is a big burden (even if the government covers parental leave salary)
edit: could also include "assholeness" in (1), could even blame it on neurodiversity