In "Young Goodman Brown," the protagonist goes into the woods to test his faith: in himself, in his wife, and in humanity. We don't know if Brown's experience was a dream or not:
Had Goodman Brown fallen asleep in the forest, and only dreamed a wild dream of a witch-meeting?
Brown could have actually experienced these things in the woods or he could have dreamed them. In either case, he had an experience that challenged his faith. And after that experience, he lost his faith in humanity. The ambiguity of whether his experiences were real or just a dream suggests that both mental/spiritual experiences and experiences in the real physical world affect the way we see the world. The uncertain conclusion is that we don't know if Brown loses his faith because of his own mental visions or because he saw evil in the real world. This complicates the closure of the story but, on the other hand, it suggests that there is a connection between our mental visions and the real world. If it was a dream, perhaps Brown was dwelling on his own doubts; not necessarily dwelling on real experiences of corruption and fallible people in his town.
Just as Brown's dream (or real experience) suggested to him that there is evil in the world, Aylmer had a foreboding dream that suggested to him that removing the birthmark might be a foolish idea.
Truth often finds its way to the mind close muffled in robes of sleep, and then speaks with uncompromising directness of matters in regard to which we practise an unconscious self-deception during our waking moments.
Brown's dream was a warning that there is evil in the world. His choice was whether or not to accept this and preserve his faith or to dwell in despair. Aylmer's dream was a warning to avoid trying to play God. He ignored the warning. Here is the difference between the two stories. Brown was overcome by his dream and was defeated by its implication of evil in the world. Aylmer ignored the warning of his dream.
In each story, the character has a dream, a vision, or an experience. What complicates the character's development is how they respond to the dream. What further complicates their response is the unreliability of dreams. How can we trust them? How do we know if they are spiritually or morally motivated? How can we be sure we interpret the dream correctly? This story was written long before psychoanalysis and Freud's work on dream interpretation. But that is essentially what's going on in these stories: the complicated mystery of interpreting dreams. Do they reflect our own doubts, real events in the world, or both?