I am wondering about developed countries in general, but my experience (and the focus of this question) is the USA and Canada.
There are laws in place to prevent discrimination. It is illegal, for example, to deny service to someone because of their skin color.
But what I don't understand, is why those discrimination laws also apply to religion? For example, denying service to someone because they are a Jew is also illegal.
If you were to deny service to someone for being a flat earther, or an asshole, or a known felon, I don't think there is any law that would stop you. Yet all three of those things, like religion, is not something anyone is born with (unlike race or sexuality), but a choice.
I am well aware that in some countries, religion is not a choice. You could be put to death if you decided to be an atheist or a catholic in many countries, for example. But in the US and Canada, nobody can force anyone to be religious, except maybe for your parents until you become old enough to move out.
What I am wondering specifically is what is the justification used to separate certain beliefs (flat earth) from others (religions), and why is it legal to discriminate against one but not the other?
Sometimes discrimination against religions even qualifies as racism (anti-semitism is described as a subset of racism in the answers to this question, and discrimination against Islam is usually described as racism in America), but it is obvious that religions are not races, so why is that?
I do not condone any discrimination whatsoever, but I just don't understand the reasons behind the laws being the way they are at the moment.
You are looking at this through the eyes of a modern. Time for some history:
One of the oldest European settlements on North America was made by Puritans, who were fleeing... government religious persecution*. One of the most influential groups in the formation of America were the Quakers, who came to America fleeing... government religious persecution.
The American Founding Fathers were (with a few notable exceptions) men of faith, and since they came primarily from various different and somewhat incompatible flavors of Christianity or generic deism and since there was a long history of flight from governmental religious persecution in their political DNA they wisely decided to prohibit the government from persecuting religions.
So religion enjoys special protection primarily because it's a historically at-risk group for persecution, especially by other religions. Which means that such protections are still relevant, they prevent a powerful religion from oppressing members of a less powerful faith.
* see Shadur's comment below for a possibly differing take on Puritan migrations.
Laws are written by people with agendas. The law is what it is because somebody campaigned for a new law and then, assuming a democratic process, had to forge a compromise with other people who may have had conflicting agendas.
If there's no law that prohibits discrimination against flat-earthers in your country, that may be because nobody has worked to convince your law makers that discrimination against flat earthers is causing enough social unrest to be worthy of their attention.
...in some countries, religion is not a choice. You could be put to death...But in the US and Canada, nobody can force anyone to be religious,
Exactly! Somebody perceived that there was a real problem or real potential for a problem, and they made an effort, and they got laws passed.
This is a Canada-specific answer, but one that is likely applicable to the US as well.
Anti-discrimination laws (or more generally in Canada, human rights laws, although are some other examples of laws prohibiting discrimination in areas such as health and safety) prohibit discrimination on a range of specific protected characteristics.
In Manitoba, for example, the list of protected characteristics includes the following in addition to several others:
(Source: CanLII http://canlii.ca/t/535vs)
These protected characteristics are both things about a person they cannot change (like age, ethnicity, etc) but also characteristics they have chosen (like religion, political party affiliation, etc).
Generally speaking, the list of protected characteristics in Canada is expanding over time, and differs depending on where you are (e.g. Manitoba employers, Ontario employers, and federally-regulated employers all have a different set of characteristics they are prohibited from discriminating against).
I would say that broadly-speaking there are two major reasons why certain characteristics are protected:
With regards to religion, the courts / human rights commissions/tribunals don't care so much as to whether the religion is a 'real' one, but whether that person is a genuine practitioner of that faith:
"Freedom of religion... consists of the freedom to undertake practices and harbour beliefs, having a nexus with religion, in which an individual demonstrates he or she sincerely believes or is sincerely undertaking in order to connect with the divine or as a function of his or her spiritual faith, irrespective of whether a particular practice or belief is required by official religious dogma or is in conformity with the position of religious officials...Although a court is not qualified to judicially interpret and determine the content of a subjective understanding of a religious requirement, it is qualified to inquire into the sincerity of a claimant’s belief, where sincerity is in fact at issue. Sincerity of belief simply implies an honesty of belief and the court’s role is to ensure that a presently asserted belief is in good faith, neither fictitious nor capricious, and that it is not an artifice." (Source: Syndicat Northcrest v. Amselem,  2 SCR 551, 2004 SCC 47 (CanLII), http://canlii.ca/t/1hddh, emphasis mine)
There are circumstances where an employer/service-provider can discriminate on a protected characteristic (a bona-fide occupational qualification) where it is genuinely connected to the job and a necessary part of it. A common example is requiring job applicants to be able to lift a certain amount of weight, or perform particular physical tasks, despite that these discriminate against people with medical disabilities unable to perform those actions. Additionally, discriminating against someone for something that is not protected (like firing an employee for being a poor performer at work) is still allowed.
I don't think there would be an awful lot of situations where someone would be discriminated against based on their Pastafarianism or Flat-Eartherism, outside of perhaps overt "We don't hire their kind"-type discrimination. I suppose the Canadian Space Agency (CSA) would be allowed to refuse to hire flat-earthers, since believing in science and astrophysics seems like a good example of a bona-fide occupational qualification for someone working in those fields.
Regarding your example of discriminating against a Jew, I think that is a uniquely bad example because there is an ambiguity in that Jews are both a religion and an ethnic group, moreover they have been victims of discrimination in the past so European societies (and their new-world descendants) tend to grant special protections to Jews on top of the general protections of any religion or race.
Some reasons for why religion is considered as extra important and worthy of protection:
To the excellent answers already posted here, I would add the additional historical detail from the specific US experience:
Religious affiliation is theoretically voluntary and self-chosen, as you point out, but in historical time it has also served as a proxy for ethnic identity. Anti-Catholic animus in the US, for example, was partially motivated by doctrinal issues (mainly related to papal supremacy and its supposed implications for national loyalty) but was also partially motivated by a dislike of the ethnicities most likely to be Catholic. In other words, people who were anti-Catholic tended to be anti-Irish and anti-Italian, and were only anti-Catholic as an incidental result of their primary bias.
Judaism historically (and not just in the US) has often been treated as both a religion and an ethnicity - to the point where Jews could not escape anti-Jewish bias even by converting to Christianity.
So in some respects providing protection against discrimination on the basis of religion is an attempt to prevent the protection against discrimination on the basis of ethnicity from being circumvented by being disguised as discrimination based on (nominally voluntary) religious characteristics.
In addition to the other fine answers, there is this: Getting discrimination eliminated usually takes more than a simple sense of fairness, if only because people who discriminate almost never believe they are being unfair. What it really takes is political clout [for example, 'gay rights' didn't exist until gays awoke to the possibility of combining into an effective political bloc]. Religions, and in particular religious institutions, have one heck of a lot of clout.
Since you state you are interested in general answers, I will present a case that is apparently different from the US or Canada.
In The Netherlands, discrimination based on political beliefs is prohibited.
Overall, Dutch law prohibits discrimination on a basis of age, sexual orientation, religion, race, gender, nationality, disability status or chronical disease, political conviction, civil status, or type of labour contract (fixed/temporary, full-time/part time).
Whether any of those is something you are born with, something you acquire, or something you choose to believe, is not relevant as far as discrimination is concerned. To take another example, to get married or divorced is a choice, but an employer cannot fire someone for getting divorced, or a school of theology cannot refuse service to people who live together without being married.
what is the justification used to separate certain beliefs (flat earth) from others (religions), and why is it legal to discriminate against one but not the other?
I doubt it has been tested in court, but in The Netherlands, I would strongly expect that if you were fired from your job as a bricklayer, lumberjack, nurse, or accountant, just because you believe in a flat Earth, you may be able to successfully challenge your termination in court, as this aspect does not affect your functioning at work for those roles. If you could show that believing in a flat Earth is part of a religious or political conviction, you would have an even stronger case.
In case of political conviction, the justification would be that we have a freedom of political association, and people have a right not to be treated unfairly as a consequence of their political conviction. Without this right, the government or business could make life difficult for supporters of the opposition (for example) by denying them jobs, which would seriously jeopardise this freedom.
I cannot speak for Canada, but part of the reason for this muddled distinction in the United States is in our Constitution.
Specifically, there is a contention between the Free Exercise and the Establishment clauses of the constitution.
Here they are.
"Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof..."
I say that these two statements are in contention with each other because of the SCOTUS interpretation on the free exercise clause. Broadly, free exercise is the source of laws aimed at preventing discrimination and persecution on religious grounds.
However, you'll notice that the establishment clause specifically prohibits the the creation of laws "respecting" an establishment of religion. Regardless of the aims of those laws. Generally, establishment has been taken to mean religious institutions and not specifically religious people or religious practices. SCOTUS has ruled back and forth over the application of these two clauses for many decades now.
So there is some disagreement even within established religions as to whether we should be passing laws regarding them at all.
Your question asks about what makes some beliefs (the earth is flat) different from others (god has a plan for my life). Philosophically we can bicker about this endlessly. Legally, the precedent has been left pretty vague. To become a religion, you need to satisfy that you are an establishment. A part of proving that your collection of beliefs constitute an establishment come from our tax law.
An over simplified breakdown would be like this:
People who believe that the earth is flat are not gathering in regular meetings in person in order to discuss and refine that belief. Nor are they unified through some other underlying principal. Except maybe a generalized distrust in scientists or authority. They do not pay tithe to a flat earth-er organizer nor submit themselves to rituals involving the existence of our planet's edges.
Without any of these practices, they have a hard time convincing the IRS that they are an established religion, and thus they cannot gain the protected status offered by the free exercise or establishment clauses of the Constitution.
With regards to the US, some of the previous answers have explained why the Federal government cannot legally discriminate on the basis of religion. The First Amendment has been fully incorporated and also applies to State governments, though most (perhaps all) independently prohibit such discrimination. However, you seem to want to know about why there are similar laws for private actors, like a restaurant.
Some seemingly private actors receive some funding or support from the government and the government stipulates that such funding cannot be used in discriminatory practices. Renting homes, especially for subsidized housing, requires potential renters to be notified about these policies. For others, they are regulated by the Federal government as "public accommodations", a term that encompasses many government facilities but also includes retail establishments. This was justified in that they presumably offer their services to out-of-state customers, so Congress could then regulate it as interstate commerce.
Some State governments have independent legislation that prohibits discriminatory action on the part of private parties in the marketplace. The states have more leeway in what laws they can implement, so long as they are not un-Constitutional.
As for why these laws have been legislated, other posters have pointed out that it just requires an interested and powerful enough group that fears discrimination. The Federal laws mentioned above were implemented during the Civil Rights Era and expanded recently for disabled individuals.
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).
German point of view here.
what is the justification used to separate certain beliefs (flat earth) from others (religions), and why is it legal to discriminate against one but not the other?
This is not the case in Germany. Inbasic law (constitution) religion typically appears as "religios or philosophical creed" or in other combinations that avoid the distinction OP is asking for:
Art. 3 (3) No person shall be favoured or disfavoured because of sex, parentage, race, language, homeland and origin, faith, or religious or political opinions. No person shall be disfavoured because of disability.
Note that this anti-discrimination list for legislation also covers a number of non-religious points that are (to a certain extent) choice rather than in-born or in other ways outside the individual in question's choice, e.g. language, homeland and religious as well as political opintions - also sex and disability are protected regardless of their "origin" (trans-sexuality, self-inflicted disability, accident/illness or congenital disability don't matter from a anti-discrimination pov). "Origin" or the question how much choice was involved getting to the particular point where the individual is in these questions simply is not a consideration.
Art. 4 (1) Freedom of faith and of conscience, and freedom to profess a religious or philosophical creed, shall be inviolable.
Art. 33 (3) Neither the enjoyment of civil and political rights, nor eligibility for public office, nor rights acquired in the public service shall be dependent upon religious affiliation. No one may be disadvantaged by reason of adherence or non-adherence to a particular religious denomination or philosophical creed.
So as long as your flat-earther is a faithful flat-earther, they're covered. Just as Christians, Jews, Atheists, Agnostics, and you-name-it.
In fact, what is colloquially called "church" in legal terms is referred to as "Religions- und Weltanschauungsgemeinschaften" where Weltanschauung is any kind of belief (Gemeinschaft = community). We do have e.g. humanitarian communities that have a legal status like, say, the Catholic Church.
Note that the basic law defines rights of people against the Federal Republic, so for private person doing service the rules may be relaxed. The "Public space" and labor law are also covered by anti-discrimination laws: if you run a shop that is open to the public and that will naturally serve many customers, you cannot arbitrarily deny services. You can throw out the "asshole" of the question in case they are an asshole because they misbehaved in your shop, though. If your service is to rent out a single room in the 2nd floor of your house, you are not forced to install an elevator so as to not discriminate against certain groups of disabled. And you are allowed to select your renter by percercieved likelihood of paying the rent.
Some more limits to anti-discrimination:
Religion is something which is very different than other beliefs. I see religion as one of the first sets of laws humanity has given itself. Religion and culture have been corner stones in the development of civilisation (some people might see this differently, but I am not aware of atheistic civilisations or societies in historial times), thus they are held culturally in higher esteem than random beliefs.
Your question is quite interesting, yet I find the specific example given for other beliefs (flat earth) poorly chosen. The shape of the earth is something deterministic, whereas a religious belief is orthogonal to science. You believe in god, you can't prove the existence of god.
Jared's answer is fine, but some more specific detail may help. As he said, you need to look at history to understand what led to these laws.
The USA and Canada are products of the British Empire, and as such the philosophies expressed in their founding were a reaction to what was going on in Britain at the time.
Centuries before the American colonies came into existence the Kingdom of England under the leadership of King Henry the 8th broke with Roman Catholicism, declaring the King (not the Pope), to have the final say on worldly matters. This had profound consequences, the most significant being the establishment of the Church of England and a protestant dynasty in England.
Religious affiliation became a question of loyalty, and England (later the United Kingdom) created laws (such as the Test Acts) which disqualified anyone not Church of England from public office. Catholics were the most obvious persecuted group, but these prohibitions also excluded minority ('nonconformist') protestant groups.
The American revolutionaries rebelled for many reasons, and religious freedom certainly was part of it. Decades later the United Kingdom (and thus Canada) finally passed the Roman Catholic Relief Act in 1829.
Religious freedom has always been a civil rights issue, and prejudice against Catholics and other religious minorities would be a regular theme in Britain and America for a long time. In America the KKK was viciously anti-Catholic in the 1920s, while in Britain Northern Ireland allowed Irish Catholics to be discriminated against as late as the 1970s.
In the United Kingdom, Canada, and America, the establishment has always been overwhelmingly protestant. The term in America is WASP: Wealthy/White Anglo-Saxon Protestant. It has always been easy for the elite to purposefully or otherwise exclude people who aren't like them, and religious affiliation is an important part of this dynamic.