The novel The Scarlet Letter is set in the theocratic and patriarchal Puritan society of the Massachusetts Bay Colony. The year is 1642, which means that this particular group of colonists settled in the area of Boston, and were part of a second wave of settlers that came from England in 1630 with the purpose of purifying the Church of England.
The specific society to which Hester and Roger Prynne had planned to go and be a part of, offered many opportunities for settlers to start new lives. However, the Puritan rule was in place. This means that, upon arriving to Massachusetts Bay, the colonists had to abide by the rules set by the magistrates. They would also have to be assigned to a spiritual leader, which was essentially a pastor that would watch over their spiritual health. Hester Prynne's assigned spiritual leader, upon her arrival, was Reverend Dimmesdale.
Hester came into the colony alone. Moreover, shortly after her arrival it was thought that her husband, Roger, had been lost at sea and was presumed dead. Also shortly after her arrival, Hester and her pastor begin an affair. It is presumably close enough to her arrival date, since, little thereafter, she becomes pregnant.
When she can no longer hide the pregnancy, she is forced to reveal the name of the father of the child. As she refuses to do so, she is not only punished with the scaffold and prison, but is also mandated to wear the letter "A", for adulterer, on her bosom for the rest of her natural life.
This series of events reveal the conflict of man (or woman) versus society. Hester Prynne arrived in the colony already a loveless wife. When her husband is presumed dead, she engages in a relationship with someone whom she actually loves. To the modern reader, Hester's actions may seem too quick but, considering her situation as someone forced to marry at a young age, they are still understandable.
However, the society of the 17th century is entirely theocratic and bound by the mandates of the Bible. This means that all commandments must be obeyed, or else punishment will ensue. Hester committed impure acts, according to the sixth commandment. She also must have involved a husband from the village (or so they thought) to commit those acts. The results were that Hester had to endure the public humiliation that was typical of her society. Standing at the scaffold meant having to tolerate the jeers of the people and being questioned publicly as to who is the father of her child. The use of the scarlet letter meant having to expose her "crime" to everyone, and expect the criticism and rejection of the general public. Imprisonment meant depriving Hester of her freedom, and further humiliating her.
Moreover, Hester was treated as a pariah: She was the topic of church sermons, of the scorn of the citizens, and of the jokes of children. She suffered entirely too much considering the actual magnitude of her crime. For these reasons, Hester could be easily considered a progressive woman for her time; one who cared less about imposed regulations, and more about her own freedom and well-being. Unfortunately, such freedom and well-being came with a price that she paid for, unfortunately, on her own.
The setting of this is Massachusetts in the 1640s. This is a time when the Puritan religion was the official religion of the colony. The Puritan system made it so that the government could enforce the moral values of the Puritan church on the people of the community.
This is why the setting is important. The society and the government of the time and place where the story is set are very opposed to Hester's actions and to the idea of individual freedom of conscience in general. This makes it easy to have a man vs society conflict because the society's values are opposed to those of the protagonist.