The main action of the novel is set in and around Salem, Massachusetts, in the 17th century, and the frame story of "The Custom House" is set in and around Salem in the 19th century. Chapter 1 opens with a clue that the narrator finds both versions of Salem to be deeply flawed:
The founders of a new colony, whatever Utopia of human virtue and happiness they might originally project, have invariably recognized it among their earliest practical necessities to allot a portion of the virgin soil as a cemetery, and another portion as the site of a prison.
The narrator is describing Puritan Salem, but this comment is a generalization about all societies. People who create a society are usually trying to "project" some "Utopia of human virtue and happiness." What they create invariably strays from their "original" vision. The novel emphasizes both the Puritan ideology that the colonists project onto Salem in the 17th century and the capitalist ideology that 19th-century Americans (that is, Hawthorne's readers) project onto it. Neither system plays out according to the original projection. The narrator is not entirely clear on the timeline of the main action, but the events take place some time before the Salem Witch Trials that began in 1692. Although Hester Prynne is not tried as a witch, the way her community shuns her as a sinner foreshadows the witch trials. This older version of Salem is shot through with aristocratic corruption, hypocrisy, and rigid behavioral expectations that no human can reasonably be expected to meet. The 19th-century version of Salem, which the narrator describes in the "The Custom House," has moved on from many of these flaws. Still, there are many newer problems. For instance, the unchecked growth of capitalism has allowed slavery to become deeply entrenched in American economics.
The novel also uses a "frontier" setting—emphasizing the line between so-called civilization and so-called wilderness—in order to challenge the idea that either version of Salem is natural and inevitable. Hester, Pearl, Dimmesdale, and Chillingworth often have their most honest conversations in the forest, away from "civilization." The novel uses Indigenous people as part of the setting, as representatives of the "natural" world beyond the borders of Salem. Hester and Dimmesdale both struggle to break free of constricting Puritan ideology that makes it impossible to live their lives peacefully. Meanwhile, Indigenous people who visit town are baffled by the Puritan rituals of public shaming that Hester and Dimmesdale each endure at different points. By placing the main action of the novel on the border between Salem and the "natural" world, the narrator emphasizes the artificiality of societal expectations and rituals. The appearance of Indigenous people as representatives of a natural world that stands in contrast to a human world can be rightly criticized as racist and dehumanizing, even if it was an unfortunately common 19th-century trope.