According to the legend, after killing Ravana when Lord Rama returned with Goddess Sita, as he stepped into Rameshwaramam, he wanted to offer prayers to Lord Shiva. Since there was no temple, Lord Shiva sent Hanuman to Kashi Vishwanath to bring the lingam of Lord Shiva.
Meanwhile Goddess Sita made a linga out of sand and Lord Rama started to worship it. This lingam so worshipped by Lord Rama came be known as Ramanathan. When Hanuman came back with the Lingam he was dejected that Lord Rama did not worship the lingam that he had brought.
Inorder to calm Hanuman, Lord Rama named this Lingam as Lingam Kashi Vishwanathan. It is a ritual followed by the devotees to offer prayers Kashi Vishwanathan before visiting the Ramanathan temple.