The subject in that case was not pregnant. You cannot fire a woman for being pregnant, even if you don’t like the circumstances of the pregnancy.
Speak for a unanimous Court, Justice Roberts wrote (at pages 21-22 of the slip opinion):
The interest of society in the enforcement of employment discrimination statutes is undoubtedly important. But so too is the interest of religious groups in choosing who will preach their beliefs, teach their faith, and carry out their mission. When a minister who has been fired sues her church alleging her termination was discriminatory, the First Amendment has struck the balance for us. The Church must be free to choose those who will guide it on its way.