In "The Scarlet Letter" Dimmesdale punishes himself in a number of ways. In Chapter 11 he tortures himself by continuously reviewing and reliving his sins in his mind. He resolves to tell the truth to his parish in the hopes that he will again have a clear conscience. So he climbs up into the pulpit and speaks of his wickedness and unworthiness. However, he does not directly reference his exact sin. His humbleness and self-loathing inspire love in his parish. They believe him to be even more saint-like than before. Dimmesdale also physically tortures himself by lashing himself with a scourge. This particular action is frequently associated with the theory that Dimmesdale is a Christ figure.
To relieve his guilt, Dimmesdale punishes himself in several ways. He goes without food and sleep for long periods of time, and he also whips himself on his back, causing cuts and bleeding. These attempts to atone for his sins do not work. Neither does his later standing on the scaffold at night when no one can see him. It is not until the end of the novel that Dimmesdale frees himself from guilt by confessing his sin and standing upon the scaffold with Hester and Pearl during the light of day. This is the only act that could free him.
In Chapter 11, "The Minister's Vigil," Dimmesdale does practice self-flagellation in which he essentially whips himself with a scourge: usually a handle to which is attached many small, leather tails, each with one or more barbs that would stick in the skin, causing greater pain and bleeding. This practice was meant to mortify the flesh and so purge the soul.
Dimmesdale also fasts, but not in a pious or healthy way. Unlike other Puritans, he fasts not to "purify the body and render it the fitter medium of celestial lumination, but rigorously, and until his knees trembled beneath him, as an act of penance." So, this fasting is not part of his worship, not a way to purify himself; instead, it is a way to atone, to punish himself for his sins.
Finally, Dimmesdale keeps late-night vigils, night after night. "He thus typified the constant introspection wherewith he tortured, but could not purify, himself." He becomes so tired that he often has visions or hallucinations. Thus, Dimmesdale is essentially sleep-deprived, malnourished, and in constant pain as a result of the injuries he's delivered to himself.
When he goes to the scaffold, it isn't an attempt to further torture himself. In fact, he hopes to find a moment of relief from the constant emotional pain and torment he feels.