it's part of the first amendment "The government shall pass no law respecting an established of religion." In other words, the United States has no officially recognized religion. The government must be secular, not promoting any single religion, or religion as a whole, and not interfering in the free practice of religion, except in cases where a religion's practices violate established law.
The reason churches and other solely religious organizations are given non-profit status is because they are non-profit. Under US law, churches must operate as non-profit organizations, They can not require payment for their religious services. If they do, they lose their status as a religious organization and any protections they received under the first amendment.
As non-profit organizations, churches are exempt from taxes. However this also limits their right to certain conduct. For example, religious organizations are not allowed to promote political candidate or raise money for political campaigns as part of their religious services. This includes not being allowed to donate church money.
This doesn't prevent a minister or other church officials from doing so on their own, but they can not do so, as part of an official church service, nor can they use money collected from church members to do so. If a minister wants to endorse or fund a candidate, they must do so completely separate from their church, and any attempt to use their church to do so could result in the church losing their non-profit status.