It is illegal to a degree, it violates rules and regulations with the IRS. When they back a politician, they are supposed to lose their church non-profit status. But that doesn't happen because any move to it would cause a huge "the government is attacking out religious freedoms/churchs".
In fact it's now a religious event every year called "Pulpit Freedom Sunday" to purposefully break these laws.