You could think of young Goodman Brown's Salem as a less, uh, cheerful 17th-century version of the bar from Cheers. It's the kind of place where everybody knows your name. And your father's name. And your grandfather's name. See a pattern here? The characters in Hawthorne's story are tied firmly together by history, common beliefs, and an interest in helping one another out. Even minor things, like greetings and small talk, help bind them together. So that's the Salem community. The weird thing is, everything we just said about "common beliefs" and "helping out" and whatnot also holds true for the villains of "Young Goodman Brown." Sometimes, community spirit has a dark underside.
Young Goodman Brown goes on his journey because he is secretly dissatisfied with community life and wants new kinds of fulfillment—at any cost.
Young Goodman Brown refuses to leave Salem because, as a Puritan, he cannot function without the community spirit that has always been a part of his life. For him, loneliness is worse than being surrounded by evil.