In Christianity, grace and forgiveness are frequently contrasted with the law. A legalistic faith (such as the Puritan one) suggests that conformity to a strict set of rules is the most important religious practice you can perform, in this world and in the afterworld. The more good you do and the fewer sins you commit, the more likely you are to go to heaven. Grace (or forgiveness), alternatively, is the concept that you are forgiven for your sins through faith.
The Puritan society in The Scarlet Letter exhibits a mixture of both legalism and grace. The narrator presents the society as essentially legalist, with its inhabitants adhering to strict moral codes and societal values. Hester’s punishment is a form of legalism. She has sinned and must be isolated from the rest of the group to keep her from contaminating them. The narrator, however, consistently offers the opinion that society, especially a religious society like this one, should be ruled by grace. At the end of the novel, Hester has been forgiven by the strict society that once punished her.
Although Hester Prynne is judged and punished in a legalistic society, she transforms her sentence, to wear the scarlet letter, into a symbol of grace rather than shame.
Even though Reverend Dimmesdale avoids confessing his sin for seven years because he fears the wrath of a legalistic society, he finds grace through confession in the last moments of his death. The peace that he finds is not dependent on the forgiveness or grace that onlookers offer, but rather on the forgiveness he finds from God and from within as he faces truths about himself.