The religion clauses are the opening of a sentence that goes on to protect speech, press, assembly and petition, and they were drafted last, in conference, out of several competing versions. What emerged was: Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof.
Two things about the wording repay attention. The first is respecting. Congress may not make a law establishing a religion, and it also may not make a law respecting an establishment, which was read at the time as leaving the state establishments alone. Massachusetts maintained a tax supported church until 1833. The clause restrained the federal government and nothing else.
The second is that the two clauses can pull against each other. A law that exempts a religious body from a general requirement protects free exercise, and can be attacked as favouring religion. A law that removes a religious element from a public programme avoids establishment, and can be attacked as burdening exercise. Most of the American case law lives in that tension.
Application to the states came through the Fourteenth Amendment, adopted after the Civil War, and it came late. The free exercise clause was held to bind the states in Cantwell v. Connecticut in 1940, a case about Jehovah's Witnesses soliciting in New Haven. The establishment clause followed in Everson v. Board of Education in 1947, on bus fares to parochial schools.