For most people, the question why be good--as distinguished from merely law abiding--is a simple one. Because God commands it, because the Bible requires it, because good people go to heaven and bad people go to hell. The vast majority of people derive their morality from religion.
This is not to say that all religious people are moral or of good character--far from it. But it is easy to understand why a person who believes in a God who rewards and punishes would want to try to conform his or her conduct to God's commandments. A cost-benefit analysis should persuade any believer that the eternal costs of hell outweigh any earthly benefit to be derived by incurring the wrath of an omniscient and omnipotent God.
Even the skeptic might be inclined to resolve doubts in favor of obeying religious commands. As Pascal put it more than three hundred years ago: "You must wager. It is not optional. You are embarked. Let us weigh the gain and the loss in wagering that God is. Let us estimate these two chances. If you gain, you gain all; if you lose, you lose nothing. Wager, then, without hesitation that He is."
I have always considered "Pascal's Wager" as a questionable bet to place, since any God worth believing in would prefer an honest agnostic to a calculating hypocrite. To profess belief on a cost-benefit analysis is to trivialize religion. Consider, for example, the decision of Thomas More to face earthly execution rather than eternal damnation. When the king commands one action and God commands another, a believer has no choice. This is the way More reportedly put it: "The Act of Parliament is like a sword with two edges, for if a man answer one way, it will confound his soul, and if he answer the other way, it will confound his body."
More followed God's order and give up his life on earth for the promise of eternal salvation. For his martyrdom--for his goodness--More has been accorded the honor of sainthood.
I have never quite understood why people who firmly believe they are doing God's will are regarded as "good," even "heroic." For them the choice is a tactical one that serves their own best interests, a simple consequence of a cost-benefit analysis. Thomas More seemed to understand this far better than those who have lionized him over the centuries.
The basic question remains. Why is it more noble for a firm believer to do something because God has commanded it than because the king has, if to that person God is more powerful than any king? In general, submission to the will of a powerful person has not been regarded as especially praiseworthy, except, of course, by the powerful person. Would Thomas More have joined the genocidal crusades in the 11th century just because God and the pope commanded it? If he had, would he justly be regarded as a good person?
Nor is this question applicable only to Christian believers. I have wondered why Jews praise Abraham for his willingness to murder his son when God commanded it. A true hero who believed in a God who rewards and punishes would have resisted that unjust command and risked God's wrath, just as a true hero would have refused God's order to murder "heathen" women and children during the barbaric crusades.
The true hero--the truly good person--is the believer who risks an eternity in hell by refusing an unjust demand by God. The great 18th-century rabbi, Levi Isaac of Berdichev, was such a hero. He brought a religious lawsuit against God, and told God that he would refuse to obey any divine commands that endangered the welfare of the Jewish people.
By doing so, Levi Isaac may have risked divine punishment, but he acted heroically. He stood up to a God who he believed had the power to punish him but who he also believed was acting unjustly. In challenging God, he was following the tradition of the heroic Abraham, who argued with God over His willingness to sacrifice the innocent along with the guilty of Sodom, rather than the example of the compliant Abraham, who willingly obeyed God's unjust command to sacrifice the innocent Isaac (or the ultimately compliant Job who apologizes to God for doubting His justice, after God had indeed acted unjustly by killing Job's children just to prove a point to the devil.)