The opening scene—even the opening paragraph of the story—helps to establish the mood and make clear Hawthorne's feelings regarding the Puritans and their brand of "justice." The narrator says,
A throng of bearded men, in sad-colored garments, and gray steeple-crowned hats, intermixed with women, [. . .] was assembled in front of a wooden edifice, the door of which was heavily timbered with oak, and studded with iron spikes.
To describe their clothing as sad-colored gives us a clue as to the general nature of these individuals; there is little liveliness about them—so little, in fact, that even their clothing seems sad. Furthermore, their hats are compared to the steeples of churches, signaling how incredibly important religion—a very specific set of religious beliefs—informs everything they do.
Women are hardly mentioned, as women were not generally considered to be very important (at least not in society), and a great deal of focus is placed on the door to the prison. It is made of oak, a wood known for its strength, and studded with iron spikes, making it sound like some kind of torture device. In fact, it basically was. Puritan prison was a nasty and merciless place, and so the thought of a woman jailed there while pregnant and even giving birth there is a horrible one.
This opening scene establishes the dark and solemn mood of the story and it foreshadows, by its reference to and description of the door, the way in which Puritan "justice" will affect the story's main characters. The Puritans, in many of their actions, favored justice over mercy, and this led to many acts that seem unjust, especially to our eyes.