Nathaniel Hawthorne came by his knowledge of the attitudes and beliefs of the Puritans naturally; he was a descendant of John Hawthorne, a magistrate during the Salem Witch Trials of 1692.
Puritans tended to believe that the woods should be avoided for both practical and spiritual reasons. Practically speaking, the woods were a place that concealed the Native Americans who compromised the Puritans' safety. Puritans had little understanding of the indigenous people's spiritual beliefs and, thus, dismissed them as devil worshipers; as a result, the woods were a place where a Puritan should not stray. To enter the woods was a symbolic act of exploring life outside the orthodoxy of Puritan belief, making it the perfect setting for Young Goodman Brown to put his faith to the test.
Salem was a colony set up as a religious utopia for the Puritans. Like its predecessor, Plymouth, Puritans believed that they had built a model "city on a hill," a new Zion that offered a model for other Christians, especially the ones they considered tainted, namely, the Quakers, Anabaptists, Anglicans, and Catholics. In "Young Goodman Brown," Salem represents a stronghold of faith. The fact that the titular character elects to step outside it—and suffers terribly as a result—suggests the intolerance, rigidity, and ultimately unrealistic nature of a religion that demands perfect conduct from its practitioners.