According to Shiv Puran here is as it goes:
Tarakasura had three sons named Vidyunmali, Tarakaksha and Viryavana. These three began to perform tapasya. For a hundred years they meditated standing only on one leg. For a thousand more years they lived on air and meditated. They stood on their heads and meditated in this posture for yet another thousand years.
Brahma was pleased at this difficult tapasya. He appeared before them and said, What boon do you want? Make us immortal, answered Tarakasura’s sons.
I can’t make you immortal, replied Brahma. I don’t have the power. Ask for something else instead. Very well, then, said Viyunamali, Tarakaksha and Viryavana Grant us the following. Let three forts be made. The first will be of gold, the second of silver and the third of iron. We will live in these forts for a thousand years. At the end of the thousand years, the forts will become one. This combined fort will be called Tripura. And it anyone can then destroy Tripura with only a single arrow, that shall be the death destined for us.
This rather unusual boon Brahma granted. There was a danava named Maya who was very good at building work. Brahma asked him to build the forts. The golden fort was built in heaven, the silver one in the sky and the iron one on earth. Tarakaksha got the golden fort, Viryavana the silver one and Vidyunmali the iron one. Each of the forts was a big as a city and had many palaces and vimanas (spaces vehicles) inside. The demons populated the three forts and began to flourish. The gods did not like this at all. They first went to Brahma, but Brahma said he could not help them. After all, the demons had got Tripura thanks to his boon. The gods then went to Shiva for help. But Shiva said that the demons were doing nothing wrong. As long as that was the case, he did not see why the gods wre so bothered. The gods then went to Vishnu. Vishnu’s suggestion was as follows. If the problem was that the demons were doing nothing wrong, the solution was to persuade them to become sinners.
Out of his powers Vishnu created a man. This man’s head was shaven, his clothes were faded and he carried a wooden water-pot in his hands. He covered his mouth with a piece of cloth and approached Vishnu.
What are my orders? he asked Vishnu.
Let me explain to you why you have been created, replied Vishnu. I will teach you a religion that is completely against the Vedas. You will then get the impression that there is no svarga (heaven) and no naraka (hell) and that both heaven and hell are on earth. You will not believe that rewards and punishments for deeds committed on earth are meted out after death. Go to Tripura and teach the demons this religion, which they are dislodged from the righteous path. Then we will do something about Tripura.
The being did as he had been asked to. He and four of his disciples went to a forest that was near Tripura and began to preach. They were trained by Vishnu himself. Therefore, their teachings were convincing and they had many converts. Even the sage Narada got confused and was converted.
In fact, it was Narada who carried news of this wonderful new religion to king Vidyunmati.
King, he said, there is a wonderful new teacher with a wonderful new religion. I have never heard before. I have got converted.
Since the great sage Narada had got converted. Vidyunmati also accepted the new religon. And in due course, so did Tarakaksha and Viryavana. The demons gave up revering the Vedas, they stopped worshipping Shiva’s linga.
Vishnu and the other gods then went to Shiva and began to pray to him. When Shiva appeared, they told him that the demons had now become evil and should be destroyed. They had even stopped worshipping Shiva’s linga.
Shiva agreed to destroy Tripura. Vishvakarma was the architect of the gods. Shiva called Vishvakarma and asked him to make a suitable chariot, bow and arrow. The chariot was made entirely out of gold. Brahma himself became the charioteer and the chariot was speedly driven towards Tripura. The gods accompanied Shiva with diverse weapons.
By then a thousand years had passed so that the three forts had become a single Tripura. Shiva instilled a divine weapon known as pashupata into his arrow and shot it at Tripura. The arrow burnt up Tripura into ashes in a split second.
While the celebrations were going on, the shaven-heads religious teachers arrived. What are we supposed to do now? they asked.
Brahma and Vishnu told them to go and live in the desert. The last of the four eras was kaliyuga and in kaliyuga, evil would reign supreme. When kaliyuga arrived, they were to come back and begin their teaching afresh.
It is somewhere mentioned in bhavishya puran or anyother scripture that one of the tripurasur was later born as mohammad of musalmans during the time of vikramaditya.I wanted to know the scripture name?
NOTE : - one of the three tripurasura's was actualy ravana's ancestor from mother's side. And the religion taught by vishnu was actually the muslim religion.