Early nineteenth-century writers were preoccupied with examining unusual mental states, the power of imagination, and the borderline between illusion and reality. The literary preoccupation with these concepts was symbiotic with developments in philosophy. Beginning especially with the works of Immanuel Kant, and his successor (in some sense) Arthur Schopenhauer, philosophers...
Early nineteenth-century writers were preoccupied with examining unusual mental states, the power of imagination, and the borderline between illusion and reality. The literary preoccupation with these concepts was symbiotic with developments in philosophy. Beginning especially with the works of Immanuel Kant, and his successor (in some sense) Arthur Schopenhauer, philosophers believed the external world, as we perceive it, is basically a projection of our minds, different from actual, unmediated reality, or the "thing in itself" as Kant referred to it.
Hawthorne is part of this literary trend that sees the outside world as what could be an illusion, or sees the power of the human mind as such that it can create its own reality. His stories generally possess a dreamlike quality even when there is no explicit mention of the supernatural. What is important in "Young Goodman Brown" is the moral concept behind the story; the unanswerable question of literal reality versus dreams or hallucinations is the mechanism by which Hawthorne expresses this theme.
In some way this is true of anything in the gothic or horror genre or in science fiction. The author is not expecting the reader, in any event, to believe this is a transcript of something that actually happened, so whether the supernatural element is real or imaginary is not the point.
It's also highly unlikely that Hawthorne himself believed in visitations by the devil, or in a literal devil at all. Much of his fiction is a reinterpretation of the beliefs of the early New Englanders in the 1600s. What was literal to them, Hawthorne appears to say, is (or should be) symbolic to us. The Puritan leaders believed in the existence, for instance, of witches, and a kind of mass hysteria caused people to see things that didn't exist.
The mysterious stranger whom Brown goes out deliberately to meet represents the perverse wish of some people to turn their backs on those things that are positive and rewarding in life. Brown's wife (named Faith, with quite obvious symbolism) urges him to stay, but he inexplicably goes out to the forest and, in effect, destroys his own life. His nocturnal vision leads him to focus on and to believe in the worst of human nature as the norm which overrides everything of value.
Whether people in general do this because of a figurative demon within themselves or because of a literal one on the outside does not matter, Hawthorne's point seems to be. The result is the same: misjudgment, false judgment, and self-destruction. In addition, purely from a literary standpoint, works such as "Young Goodman Brown" are more interesting, more compelling, when capable of multiple interpretations.
Apart from the illusion versus reality "mechanism," which is central to Hawthorne's work, we find him posing the question of how much in human life is caused by God or fate, how much is the result purely of human intentions and misdeeds, and how much is due to pure chance. Goodman Brown's excursion functions like the catastrophes in "The Ambitious Guest," "Rappaccini's Daughter," and "Lady Eleonore's Mantle." As with anything in life, humanity can only guess at what the ultimate cause of misfortune is.