In addition to the other excellent answers, I would add that one must consider the beliefs of the Puritans. They were constantly looking for verification that someone was or was not a "chosen" one of God, destined for the kingdom of Heaven. By branding Hester in this way, it was one less to worry about (there were only so many spots, you see) but also benevolently consorting with Hester in any way might also indicate to others that the consorter was one of the lost. I know it's confusing, but that's the way it worked. "Who's in, who's out" was constantly on the Purtian radar (so to speak).
Puritans understood themselves as members of a community, so that a sin would not be a private thing but something public that the entire community should be aware of. This sort of punishment would strengthen the bonds of the community, their identity of themselves as a group. The punishment would make the sinner an outsider of the community for she transgressed the boundaries of acceptable behavior. Finally, this public condemnation would emphasize the goodness of the community which would understand itself in opposition to such sin--it would reinforce their mission to be "good"--at least on the outside.
Due to the fact that there is no proof that Hester's husband is still alive, and therefore she could technically be a widow, coupled with her young, beautiful appearance, the magistrates feel that "branding" her with the scarlet letter is adequate punishment. Hester will be reminded daily of her sin, as she is never to take of the letter in public. It also serves as a public notice, everyone she comes into contact with, will see her sin. Knowing she will be humiliated every day(or so they think) seems just punishment.