Two elements of the Gothic that appear in "Young Goodman Brown" are the uncanny and the unheimlich, which are related concepts.
Freud wrote that we experience the uncanny when the ordinary becomes strange or eery. This is connected to the unheimlich or unhomelike, which is when "home," or the familiar, suddenly transforms into that which seems threatening or creepy. A haunted house is an example of the unheimlich—it is both a home and unhomelike at the same time.
Freud connected the uncanny to the return of the repressed. We repress the parts of ourselves we don't want to see, especially violent or sexual desires that we find socially unacceptable. To catch a glimpse of such a part of ourselves is startling and disorienting, just as it is to see a reflection in a mirror or a photo of the back of bodies, which are usually out of view. When we feel this disorienting sensation of the uncanny, we are experiencing our repressed desires.
Young Goodman Brown finds himself, as he travels through the woods, entering into a eerie Gothic landscape that becomes more and more unheimlich as he goes deeper into it. When he gets closer to his destination, he finds,
The whole forest was peopled with frightful sounds; the creaking of the trees, the howling of wild beasts, and the yell of Indians; while, sometimes the wind tolled like a distant church-bell, and sometimes gave a broad roar around the traveller, as if all Nature were laughing him to scorn.
Goodman Brown normally knows the forest, but now it has become howling and unfamiliar—itself but not itself.
Likewise, he sees all his neighbors in an eerie or uncanny way when he encounters them at the devil's ceremony. People that were homelike and familiar to him, people he thought pious and good, such as Goody Cloyse and Deacon Gookin, suddenly show themselves as evil. Even his wife, Faith, whose pink ribbons symbolize her innocence, shows up at this evil ceremony.
Deep in the forest, the setting becomes an unheimlich version of a church service, a service worshipping the devil, not God. Like a typical church service, there are "hymns," an altar, and the tops of pine trees ablaze like "candles"—but this is unlike any church Goodman Brown has ever attended.
If the Gothic genre puts us in touch with our repressed side, this story shows Goodman Brown facing his unconscious temptation to give in to his darker impulses. The story also shows his loss of innocence. Whether a dream or real, Goodman Brown is coming to grips with the idea that all humans, including he and his wife, may hide a dark, hidden self behind the public front they exhibit to the world.