The pillory was an effective means of punishment because the person who was being pilloried had no way to hide their shame. The offense was made public and they could not even hide their shame from their friends and neighbors. It is particularly effective in TSL because it provides a stage for the "confrontation" between Hester and Dimmesdale.
It is a successful literary device because it provides Hawthorne with a stage for dramatic irony, presenting the reader with Pearl's father without revealing who he is at this point and letting the plot unravel. It would have been difficult to present this public confrontation without the pillory. The scene also allows Hawthorne to introduce the townsfolk who are watching the punishment, revealing their general cruelty (although there is some sympathy in a couple of them), and introducing the city which functions as a character in the story.
Of course, when Hester leaves the pillory her punishment is only just beginning, but we have learned many things that will be developed during the story.