Your intuition is correct (in that there's no over-arching precedent or Constitutionally-derived right that makes it illegal), but it's specifically banned under Title VII of the Civil Rights Act as per a 1978 law modifying the act. https://www.eeoc.gov/statutes/pregnancy-discrimination-act-1...
... Which goes to the court ruling that's the topic of the article: Congress has the power to decide these issues.