"We didn't hire you because we think women make better caregivers" is just as illegal as "We didn't hire you because we think men make better middle managers."
http://www1.eeoc.gov/eeoc/newsroom/release/5-2-18.cfm
>The Children's Home, Inc., a Tampa nonprofit child care organization also known as the Children's Home Network, will pay $18,000 and provide training for its human resources and management employees to settle a sex discrimination lawsuit brought by the U.S. Equal Employment Opportunity Commission (EEOC), the agency announced today. The EEOC's lawsuit charged that The Children's Home violated federal law when it refused to consider a male employee, Luis Vasquez, for a position in its maternity home program based on his sex. The suit further alleged that, Vasquez, after voicing his concerns about the company's refusal to consider him because he is a male, was prevented from applying to any other positions with the organization.
https://www.eeoc.gov/eeoc/newsroom/release/7-30-18b.cfm
>BALTIMORE - Park School of Baltimore Inc., a private school in Pikesville, Md., violated federal law when it refused to renew the employment contract of a male softball coach because it preferred female leadership, the U.S. Equal Employment Opportunity Commission (EEOC) charged in a lawsuit it announced today.
Of course there are exceptions to gender discrimination that does allow an employer to hire on the basis of sex (I.e. bonafide occupational qualification).
Protected classes are qualified for special treatment in law and policy, particularly in the context of employment law.