Can a person be compelled to violate their religious beliefs if those
beliefs are racist?
No. But a person can face strong economic pressure to do so.
Someone can be forced to choose between operating a public accommodation or other business (e.g. renting apartments) subject to laws barring racial discrimination in a legal way, or not engaging in those activities at all. But, not all economic activities are subject to these laws.
Heart of Atlanta Motel, Inc. v. United States, 379 U.S. 241 (1964), is still good law, and would even survive most attempts to claim a religious exemption. But recent caselaw has slightly trimmed its scope at the margins, when a religious objection is claimed.
If someone is determined to make racially discriminatory decisions in one's business or employment activities which they feel are compelled by their sincerely held religious beliefs, while being similarly committed to complying with the law, this dramatically reduces that person's economic options to make a living. But it doesn't eliminate this person's economic options to make a living entirely.
Notable Exemptions From Discrimination Laws
Masterpiece Cakeshop as clarified and expanded by 303 Creative LLC v. Elenis, basically stands for the proposition that a business based upon selling your own personal expressive activity cannot be regulated in a way that alters that personal expression.
Similarly, religious organizations are generally exempt.
Lots of businesses that don't involve coming into contact with customers, and do not have employees (or have very few employees, such as only employing family members), for example, running a small gold mine or a small family farm, are also exempt.
Likewise, lots of lower level employees do not have job responsibilities that give them an opportunity to make legally regulated decisions in a racially discriminatory manner, although most managers who supervise other employees, and many employees who have "forward facing" customer service roles do.
The Practical Reality
The practical reality, as of the year 2024 in the U.S., is that U.S. cultural norms have evolved, over the last sixty years or so, to the point where very few people and very few religious organizations claim that they are religiously compelled to act in a racially discriminatory manner.
This doesn't only mean that the issue comes up less often. It also means that the sincerity of the religious beliefs of someone who does claim a religious objection is viewed with more skepticism by judges and juries as an evidentiary matter in a trial seeking to enforce anti-discrimination laws involving racial discrimination. The overwhelming extent of the overall societal shift undermines the credibility of someone who claims to have a sincere religious obligation to discriminate based upon race. And, if a judge or jury concludes that the claimed pro-discrimination religious belief is not actually that person's own sincerely held religious belief, then a religious objection defense to enforcement of an anti-discrimination law against them will fail.
But many people and many religious organizations in the U.S. sincerely claim that they are religious compelled to act in a discriminatory manner towards LGBT+ individuals. This is why Masterpiece Cakeshop and 303 Creative LLC v. Elenis involved customers celebrating same sex marriages and not, for example, interracial marriages.