The establishment clause arose during James Madison’s efforts to have the constitution ratified. Virginia had disestablished the gentry-supported Church of England during and after the American Revolution. This left the Baptists in a position of political influence. Col. Thomas Barber, an opponent of the constitution in Madison’s home of Orange County, Virginia, began a campaign for election to the state ratifying convention. He garnered support among the local Baptists by warning them that the constitution had no safeguard against creating a new national church. To head off Barber’s challenge, Madison met with influential Baptist preacher John Leland and promised that, in exchange for Leland’s support of ratification, he would sponsor several amendments that were ultimately combined into the First Amendment. The Establishment Clause was established mainly as consensus among all of the religious groups in American during 1787, to prevent one religion from having too much influence.
Wikipedia