What purpose do nightmares serve in the world of The Sandman? In the second volume of The Sandman Library (The Doll's House), Dream spends most of his time tracking down and dealing with a number of errant nightmares (Brute, Glob, and the Corinthian). He refers to these as "his creations" many times, unforming some (to be reformed later) and banishing others (for a few thousand years, implying that they will eventually return).
What purpose do these creatures serve? Dream seems to take his "job"1 very seriously; this seems to include caring for the well-being of sentient creatures -- the other main story of The Doll's House, for example, was that of the dream vortex, which posed a great danger to anything that dreamed, and Morpheus did his best to avert the impending disaster. In this volume, he also disbands and attempts to rehabilitate the Collectors.
One could argue that it's possible that while nightmares are not good for individual humans, they serve a greater purpose for humanity. The basis for that argument would be that the focus of Morpheus' care for sentient creatures appears to undergo some shift from humanity-only to include individual humans, and the nightmares were created long before Dream cared much for lone individuals. The only caveat that accompanies this interpretation is the apparent absence of a benefit for humanity in general. (At least, I don't see one.)
It cannot either be that nightmares are things that humans (or sentient beings) find in their minds, and that Dream does not remove -- in this universe, nightmares are the creations of the King of Dreams. They are things that he expressly created, for some purpose that escapes my understanding at the moment.
Do they serve some purpose in-universe? Are they just a plot device, or a metaphor? (Something else?)
When I searched Google, I was not able to find much about nightmares. The shared Wikia page for dreams and nightmares says (without a source) that "Nightmares are beings created by Dream to populate his realm and to help him with various tasks." This does not, however, explain what the purpose of nightmares is. TV Tropes seems to treat them all as mere "Nightmare Fuel," but I think there should be a greater purpose in them, especially since Neil Gaiman is such a careful writer, and Dream is such a careful guardian.
1 I'm not sure what, exactly, that job is. In three volumes of The Sandman, I have yet to see a job description. Perhaps that will come later.