As soon as Lord Rama returned to India after defeating Ravana, a few sages, headed by Rishi Agastya, advised him to establish a Shivalinga that would be remembered by his name. Accordingly, Rama scheduled an auspicious time and asked Lord Hanuman to bring a Shivalinga from the Kailasa Parvat. As expected, Hanuman started off for the Himalayas with great enthusiasm. But Shiva, who probably wanted to initiate a divine play, took his time in appearing before Hanuman. Because a Shivalinga had to be established before the set deadline, Rama placed another Shivalinga, which Goddess Sita had built, at the destined location. He then hit the earth with his bow to create a well and offered its water in the new temple.
When Hanuman returned with a beautiful statue, he saw that Rameshwaram had already been established. With slight despair, Hanuman said, “It appears that my effort has turned futile.” Sensing that Hanuman is feeling ignored, Rama responded, “I know the karma of every being that has been born or will be born. Do not let the slightest gloominess reach your mind, for all sorrows are a hindrance to jnana. Instead, focus on your eternal self-illuminating soul. Once you establish yourself in oneness with the Supreme Soul, you will see that all your actions are my own and all my actions are your own. Please perceive that the Shivalinga which I have established has also been placed by you.” Finally, Rama said, “Now, you should establish the Shivalinga that you have brought from Kailasa. It will be known in the three worlds by your name, and jivas will visit Hanumadisvara before they visit Rameshwaram.”
* This story is from the Skanda Purana. Alternate versions tell us that Rama established Rameshwaram before visiting Lanka.