There are 2 different versions of the story - that at the time of Srimad Ramanujacharya, after Sri Ramanuja dug up and found the moolavar at Melkote Thirunarayanapuram, he was feeling sad over not having found the matching urchavar for Sriman Narayana. At this, Sriman Narayana is said to have appeared at a dream of Srimad Ramanujacharya and told him about his whereabouts in Delhi with the daughter of the sultan. Thereupon, Srimad Ramanujacharya set out for Delhi and spoke to the sultan, who after being convinced of Srimad Ramanujacharya's devinity (Sri Ramanuja actually told the sultan the vigraha is with his daughter which no one else knew) showed him the inner chambers of his daughter. Then Srimad Ramanujacharya is said to have called out to the idol and the idol is said to have "run away" to the great saint's lap. Thereafter which the young daughter who had fallen in love with the Ranganatha idol also followed the idol suit to Melkote where she merged with the idol.
Here is another version of the story pertaining to Sri Rangam:
The Saga of Thulukka Naachiyaar, Sri Rangam | kshetrapuranas