In Skanda Purana, Prabhas Khand Chapter, Lord Shiva tells goddess Parvathi about how Somnath Lingam came into existance.
Chandra Deva Looses his Lusture
Lord Shiva explains about the reason why Chandra deva had to install a Shiva linga at Prabhas
Kshetra. As Daksha had got married twenty seven of his daughters to Chandra
Deva. Chandra Deva was only attached to Rohini, who was one of them and neglected others. When Daksha came to know about this he cursed Chandra Deva as the result of which he lost his luster.
Chandra Deva Does Penance twice
Chandra Deva(Moon) then did an austere penance for thousands of years to get help from Lord Shiva. At last Lord Shiva became pleased and appeared before him and told some processes of Worshiping. Subsequently, Chandra Deva got a divine Shiva lingam installed by Brahma and worshiped it for thousands of years. Lord Shiva appeared once again and expressed his willingness to fulfill any wish Chandra Deva expressed. Chandra Deva requested Lord Shiva to dwell in the very Shiva Lingam he had been worshiping till then. Lord Shiva revealed to him that there was no question of dwelling in the Shiva Lingam as he had never abandoned it in the first place. Chandra Deva had regained his luster on account of his arduous penance.
Existence of Somnath Lingam
Lord Shiva blessed him and said Since you have regained your luster (Prabha) by your austere penance, this holy place will become famous as ‘Prabhas Kshetra’.
This Lingam would be named upon you and become famous as Somnath Lingam. Having blessed Chandra Deva thus, Lord Shiva disappeared. Later on Chandra Deva instructed Vishwakarma to build a magnificent temple at the sight. He also built a city nearby so that all the priests who were supposed to supervise the rituals of worship could live there.