If you were to deny service to someone for being a flat earther, or ... a known felon, I don't think there is any law that would stop you.
I disagree. There are some laws, in at least some parts of the United States, that may prohibit discrimination against a felon, while that may be perfectly allowed in other places. This just isn't one of the criteria that happened to be included in the written law that was passed at the national level (as I understand it), but local laws may also apply.
As for "flat earther", I would totally expect that to be treated as a religion, as the flat earthers are often quite aware of some of the evidence against their position, and yet they maintain their position based on faith.
why is it legal to discriminate against one but not the other?
As a full-fledged believer in a major religion, I do see value in freedom of religion. I mean, ultimately, I believe in an all-powerful God who is all-knowing, and so judgement will come eventually, and in that sense, any freedom of religion is temporary. There is no "long term" (eternal) freedom of religion. However, for the short term, it is good for our government to honor freedom of religion.
This is not because I see any good in people worshiping wrongly (such as Satanic worship, which is completely wrong in my opinion). However, the reason why freedom of religion is good is because of this: a person's relationship with God should be about their own personal decision about what relationship to have with God. No government is qualified to decide that relationship for a person. For that matter, neither are employers. If you want to be a "bricklayer, lumberjack, nurse, or accountant," (referencing the list that gerrit provided in gerrit's answer), you should not be required to convert to a religion that you think is incorrect just because you want to have a job in that profession. To try to eliminate (or, at least, reduce) (potential) employers from abusing their (potential) power by trying to impose religious values, protections were put into law.
But what I don't understand, is why those discrimination laws also apply to religion?
To some degree, they don't. A church may decide to not hire somebody based on their religious ideas. (The same is true for a religious school, which teaches standard school subjects but also has classes about a specific religion, and teaches the tenants of the religion.) Such discrimination is absolutely necessary for such organizations, since they need to be able to hold people to religious standards. Otherwise, the religious teachings may get watered down by the inconsistency of people who don't hold those beliefs. A person might be qualified to be a "teacher" based on an ability to teach, but a church isn't going to want someone that they consider to be a "false teacher" to continue to teach falsehoods. And so, in order to try to present a unified voice of core religious teachings, such religious organizations need to have the ability to be selective.
Sometimes discrimination against religions even qualifies as racism ([...] discrimination against islam is usually described as racism in America),
This is just because when I first see somebody walking down the street, or I meet a person during a brief half-hour interview, I might not be able to identify which religion guides them. However, I can often notice traits that are very common in Islam, such as Arab traits including skin color. Wearing a turban might indicate involvement with a predominantly Islam nation, or someone from India (which is more Hindu than Islam), or the Sikh religion (rather than Islam). Regardless of which of those religions someone may be, turbans are less popular among Jews and Christians, so this could be a way for someone to discriminate (negatively or positively).
Race can often be determined with higher reliability, based on recognizing race-based characteristics (like skin color) or cultural characteristics, while individual religious decisions may be harder to determine (and therefore harder to use for discrimination).
Laws or complaints about racism may be due to a perception that racism is simply more common (even if religiously motivated), or just because of strong sentiment of people despising racism (since race is less controllable than religion, discriminating based on that will be more offensive to at least some people).