Pregnant employees are undoubtably less of an investment for the company when you consider paid leave. In fact the company might actually lose money on you.
This is a lot different than racial, sex, or age discrimination as a result of social bias or stereotypes.
So it makes sense there is discrimination from companies and managers - especially competitive companies where the managers are paid based on their team performance. In a truly capitalist market you would rarely hire someone at risk of becoming pregnant.
That leaves me to believe the only good solution is some type of mandatory leave for both men and women. Rather than trying to avoid the discrimination (via penalties, laws, etc.), force an equal leave rights for men and women so the companies no longer have to consider a particular gender over the other.