There certainly is a lesson to be learned from "Young Goodman Brown." Hawthorne was using an extreme example to illustrate the fact that there is good and bad in every human being. We should not accept other people at face value. Many people who seem honest and friendly have ulterior motives. Some people who are actually wicked and dangerous manage to hide their true natures behind masks of innocence and benevolence. The fact that Young Goodman Brown's "dying hour was gloom," was only due to the fact that he had sustained such a horrible disillusionment about humanity on the night that Hawthorne describes in his story. Humanity hasn't changed since Hawthorne's time.
Arguably, the lesson of "Young Goodman Brown" is to not prejudge others and assume that they are guilty of committing crimes when you do not have any proof. When Brown meets with the devil in the forest, for example, he is told that from now on, he will see other people from the perspective of their sins:
By the sympathy of your human hearts for sin ye shall scent out all the places—whether in church, bedchamber, street, field, or forest—where crime has been committed, and shall exult to behold the whole earth one stain of guilt, one mighty blood spot.
This does indeed happen: the next time that Brown goes into the village, he is a like a "bewildered man." He calls the Deacon a "wizard," for example, and distrusts his wife, Faith, because he has a new outlook on life. He sees evil all around him but, most importantly, it lacks any factual basis.
In the final paragraph of the story, the reader learns that this new outlook is destructive:
A stern, a sad, a darkly meditative, a distrustful, if not a desperate man, did he become, from the night of that fearful dream.
Goodman Brown, therefore, demonstrates that we should never prejudge others because if we do, we are certain to live a miserable and distrusting life and become alienated from those around us.