Koteshwar temple is a place where Lord Shiva himself stopped so that he could meditate while he was going to Kedarnath. The temple has been here since the time of Bhasmasur as it relates a story between Lord Shiva and Bhasmasur. Bhasmasur, the demon had a power which granted him the power to turn anyone into bhasma or ashes. He tried to take the power out on Lord Shiva and so Lord Shiva kept wandering in different places.
Lord Shiva finally stopped at this cave and meditated to the name of Lord Vishnu who came and rescued him and killed Bhasmasur. The place later became a temple known as Koteshwar Mahadev Temple.