Kashi Vishwanath Temple when this hymn singing the glories of Shiva, could be composed due to the grace of Lord Shiva.
The temple houses the famous Vishwanath Jyotirlinga.
There is another story which says that this hymn was sung on behalf of Kakbhusundi to appease Lord Shiva and seek his blessings. Kakbhusundi was not a crow earlier and was born in Ayodhya as a Shudra. He was a staunch devotee of Lord Shiva and had an aversion for all other forms of God including Rama. Once a draught ravaged Ayodhya and he migrated to Ujjain where he met an ardent devotee of Lord Shiva, having great respect for Lord Vishnu as well.He tried to convince Kakbhusundi,“There is only one path of worshipping Lord Shiva and that is devotion to Lord Rama. It is said that Lord Shiva himself constantly chants of the name of Rama.”
One day Bhusundi was doing japa in Lord Shiva's temple when his guru or spiritual preceptor walked in. Ignoring him, he went on with the incantation. The guru overlooked this rude behaviour but Lord Shiva, being Adi Dakshinamurti could not and spoke furiously through an asarira-vaak, "You stupid fool! I've had enough of your arrogance. Now I'm going to curse you!" When the preceptor heard this, he was very anxious whereas young Bhusundi trembled in fear.
Lord Shiva continued: "Since you were too lazy to stand up and offer due respect to your guru when he walked in, I'm going to turn you into a serpent. Henceforth you will become a python and dwell in the hollow of a tree!" When Lord Shiva raged thus, the guru was overwhelmed with compassion for his errant disciple. He begged Lord Shiva for mercy and sang his glories in the 'Rudrashtakam'.This beautiful hymn of eight verses is given in the Uttarakhand of the Ramcharit Manas (107th doha or couplet). Sung on behalf of Bhusundi, it nullifies the curse and transforms it into a blessing instead.
Lord Shiva was pleased with the Rudrashtakam and confirmed that he would grant a boon.The preceptor asked for devotion of Shiva's feet and the forgiveness of Bhusundi who was ignorant because of worldly illusion.After having listened to this wonderful stuthi or eulogy, Lord Shiva assured the Brahman, “Even though Bhusundhi has sinned, just because of your prayer, he will go through cycles of births and deaths but not undergo the painful suffering."
Lord Shiva went on to clarify, “ And since Bhusundi was born in Ayodhya and worshipped me, he will achieve devotion for Lord Rama with the passage of time."
Soon after, leaving the temple, Bhusundi went into the forest, where he dropped his body and started the process of transmigration. He was born as a serpent and in a thousand other sub-human forms thereafter.
Finally he was born in a family of Brahmans and became a great devotee of Rama.When his parents died he went to the forest where great sages raved about the formless virtues of God but he just wanted to listen to the glories of Rama. They cursed him to become a crow but asked him to meditate on the child form of Rama.
Since the past twenty-seven kalpas or ages, Kakbhusundi lived in the Nilgiri Mountains and sang the glories of Lord Rama. When Lord Shiva appeared on earth,Kakbhusundi was Rama's companion in child play and narrated the Ramayana to Garuda, the celestial vehicle of Lord Vishnu.