Srimad-Bhagavatam: Canto 3 - Chapter 1 - Verse 40


सृष्ट्वा भूतपिशाचांश्च भगवानात्मतन्द्रिणा ।दिग्वाससो मुक्तकेशान् वीक्ष्य चामीलयद् द‍ृशौ ॥ ४० ॥


sṛṣṭvā bhūta-piśācāṁś cabhagavān ātma-tandriṇādig-vāsaso mukta-keśānvīkṣya cāmīlayad dṛśau


The glorious Brahmā next evolved from his sloth the ghosts and fiends, but he closed his eyes when he saw them stand naked with their hair scattered.


Ghosts and mischievous hobgoblins are also the creation of Brahmā; they are not false. All of them are meant for putting the conditioned soul into various miseries. They are understood to be the creation of Brahmā under the direction of the Supreme Lord.