First of all, Masterpiece Cakeshop v. Colorado Civil Rights Commission 584 U.S. ___ (2018) (Docket via Justia) was not settled on the merits. The Commission decision against the cake maker was overturned on procedural grounds, and no final decision on the merits has been made to date, to the best of my knowledge. And as Trish points out, the baker claimed that the law was, in effect, forcing him to use his individual artistic talents to make a statement endorsing a view that he deemed religiously wrong.
Note that anti-discrimination laws are not an inherent right, they are statutes, created in the US by Congress and the state legislatures, and they prohibit just what the legislators have chosen to prohibit. For most of the history of the US there were no such laws, and Congress could repeal them tomorrow if it chose. So in a sense the only real reason why the laws grant certain religious exemptions is because Congress (or the various state legislatures) has said so.
The actual exemption is found in 42 U.S. Code § 2000e–1 (a) which provides that:
This subchapter shall not apply to an employer with respect to the employment of aliens outside any State, or to a religious corporation, association, educational institution, or society with respect to the employment of individuals of a particular religion to perform work connected with the carrying on by such corporation, association, educational institution, or society of its activities.
Thus it exempts a "religious corporation, association, educational institution, or society" from complying with that part of the anti-discrimination law that refers to employment. That would particularly be 42 U.S. Code § 2000e–2 (a) which provides that:
(a) Employer practices -- It shall be an unlawful employment practice for an employer—
(a) (1) to fail or refuse to hire or to discharge any individual, or otherwise to discriminate against any individual with respect to his compensation, terms, conditions, or privileges of employment, because of such individual’s race, color, religion, sex, or national origin; or
(a) (2) to limit, segregate, or classify his employees or applicants for employment in any way which would deprive or tend to deprive any individual of employment opportunities or otherwise adversely affect his status as an employee, because of such individual’s race, color, religion, sex, or national origin.
There is a further similar but more limited exemption in 42 U.S. Code § 2000e–2 (e)
It would pretty obviously violate the free exercise clause to require a religious organization to hire, say, priests, ministers, or other religious leaders regardless of religion. But the exemption goes farther than that. A church may discriminate on religion, or on race or sex, say, in hiring janitors or other people whose functions have nothing to do with religion. Nothing in the US Constitution requires that broad an exemption. But on the other hand, nothing forbids it either. That was the decision of Congress, and was no doubt in part the product of a political compromise. There is a long history in the US of providing churches and other religious organizations a degree of exemption from ordinary laws, and this is in line with that tradition. Beyond that, why this particular exemption and not a somewhat narrower one was chose, is a matter of politics, not law.
The question asserts:
Government sanctioned religions prayer is already illegal per "Engel v. Vitale".
That is an over-broad reading of Engel v. Vitale, 370 U.S. 421 (1962). In that case (as the Wikipedia article puts it):
the Court ruled that it is unconstitutional for state officials to compose an official school prayer and encourage its recitation in public schools, due to violation of the First Amendment. ... The Court held that the mere promotion of a religion [by the government] is sufficient to establish a violation, even if that promotion is not coercive.
The case focused on the fact that the government had composed the text of the prayer in question, and that encouragement to recite it was a matter of official government policy. That is quite different from permitting private individuals or organizations to say voluntary prayers, or make hiring decisions based on religious distinctions.