Purana Jyotisha Sangraha · by Vyasa
Chapter 14 · Ujjain: Shani and the Planet Tirthas
स्कन्दपुराणम् : अवन्त्यां शनिः ग्रहतीर्थानि च
इत्युक्तो गुरुणा भूयो वशिष्ठेन महात्मना ।जगाम त्वरितो देवि महाकालवनं शुभम् ।ददर्श तत्र तल्लिंगं दुष्टदुःस्वप्ननाशनम् ॥ ५४ ॥
From the Skanda Purana, print Avantya Khanda, Chaturashiti-linga-mahatmya ch 80, verse 54.
So told again by his teacher, the great-souled Vasishtha, he went quickly, O Goddess, to the lovely, auspicious Mahakala forest. There he saw that linga (the stone symbol of Shiva) that destroys evil dreams.
Simple meaning: The king went to Mahakala forest and saw the linga that destroys bad dreams.
नष्टाः सर्वेपि दुःस्वप्नाः सुस्वप्नाश्चाभवंस्तदा ।
His bad dreams ended, and the king went back to Ayodhya and ruled happily.
तदाप्रभृति देवोऽयं सुस्वप्नेश्वरसंज्ञकः ।
From then the god was famous as Susvapneshvara, who destroys all bad dreams.
अष्टम्यां च चतुर्दश्यां देवं स्वप्नेश्वरं शिवम् ।
Seeing Svapneshvara after a bath in the Shipra on the 8th or 14th is said to end bad dreams.