There are ways to keep this from happening. Our church constitution specifies that the minister is hired for an indefinite term. Before I accepted the call, I asked the board to approve a policy listing the specific reasons that I could be fired. The list is pretty common-sense--basically, as long as I behave ethically and remain faithful to God's word, I can't be fired. If the congregation fired me for something not on the list, I could sue them for breach of contract.
Not all congregations put these limitations on themselves. But several things will stop them from firing the pastor:
1) Choosing another pastor is a lot of work and is disruptive to the congregation. If they choose another pastor, they'll have to go through a lot of difficulty. If they continue to fire pastors, the congregation will eventually fail entirely (remember, there's no diocese to support a congregation in trouble; if the church runs out of money, it will close).
2) If they fire me, they can get a pastor who won't bug them about money, but they won't have me. The pastor who trained me talked about "pastoral credit." When I show my commitment to the congregation--even when they get on my nerves--they build a commitment to me--even when I get on their nerves.
3) If the congregation fires me, they have to get someone else. It's normal to ask what happened with the last pastor. When they say, "he convicted us of sin so we fired him," they're going to have a hard time replacing me. And they might be able to cover up the reality once, but before long they'll be known as the church that can't abide preaching about money. Once their reputation is known, anyone who comes to interview will be able to say in advance, "you can't fire me because you don't like the content of my preaching."
4) A good shepherd will sacrifice his life for the flock--if a pastor won't even risk his job, he's not really a minister of the Gospel. And that will show in other ways. Most Christians know that they're better off with a minister who makes them uncomfortable than one who tells them only what they want to hear.