Guilt is a strong theme in Hawthorne's The Scarlet Letter. In general terms, decisions are based on the combined experiences that an individual has been exposed to. Looking at Arthur Dimmesdale, I believe that his guilt cannot help but originate based first upon his religious upbringing, but is then reinforced by way of society. Both things affect Dimmesdale's grief, but because there is no separation between his upbringing and society—both being grounded in Puritanical theology—the two elements are join to press obedience on the righteous, and guilt on sinners (which realistically should apply to everyone in the congregation).
The first and therefore greater source of guilt is more readily understood in light of the following scripture. Proverbs 22:6 says:
Train up a child in the way he should go: and when he is old, he will not depart from it.
We can assume that when Dimmesdale sleeps with Hester, he is not turning his back on his faith—he is making a serious mistake, especially in light of what he has been taught growing up and what society demands of its members. Adultery was a serious crime among the Puritans. While some who committed adultery were executed, some were not. For example, Hester is spared because she is pregnant.
Dimmesdale never comes forth to claim responsibility in their affair, so his community does not punish him. However, his upbringing is such that the guilt he endures comes from his own recognition of his transgression. His punishment is much harsher than those society could have devised (unless they had killed him) because Dimmesdale punishes himself unceasingly with physically assaults against his body, like beating. He also suffers emotionally, mentally and spiritually. While I believe that the theocracy that rules the community in which he lives stresses the importance of living a moral life, I believe the guilt begins based upon his upbringing and then is continually reinforced by society. I see no way to separate the two, but feel that the teachings of Puritanism that he was raised with have a stronger effect on him.
A clear indication as to the depth of Dimmesdales' guilt is found as follows:
...By the constitution of his nature, he loved the truth, and loathed the lie, as few men ever did. Therefore, above all things else, he loathed his miserable self.