"Young Goodman Brown" is often said by critics to be, among other themes, a comment on the strict religious culture of the early Puritans. In such a strict culture, the people/characters are faced with an irreconcilable opposition between goodness and evil. As such, those adhering to the radical religious codes and laws would react with outrage at anything remotely evil. This was the tragedy of the Salem Witch Trials. And in the story, Brown himself reacts with similar outrage. In fact, after witnessing (as a dream or in reality) that evil exists among his pious townspeople, Brown decides that all is lost. Rather than admit that evil and good exist in the world, Brown takes the radical approach that such a balance is not possible.
So, if Brown is so determined to be good and righteous, why does he go into the forest, knowing some evil might lurk there? Coming from such a strict, religious culture, he goes out of simple curiosity or consternation at the situation described to him. Above all, Brown goes on this journey to examine "faith": his faith in himself, his wife's faith in him, his faith in his wife and humanity as a whole. Hawthorne metaphorically alludes to Brown's testing himself early in the story, though the context is literally in reference to a business journey:
My journey, as thou callest it, forth and back again, must needs be done 'twixt now and sunrise. What, my sweet, pretty wife, does thou doubt me already, and we but three months married?
Believing in this strict opposition, good/evil, all or nothing, Brown seeks proof of single-minded belief in goodness, but he loses his faith on his journey to the forst because he sees how the mere suggestion of evil corrupts everything. Seeing the possibility for evil in the world and in others he thought to be righteous, he retreats into despair and loses faith in himself as well.