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.