The story goes back to the Dwapar Yuga when the Magadh King Jarasandh was a tyrannic ruler. He had two daughters, Asti and Prasti. He got both his daughters married to the king of Mathura, Kansa who was also the maternal uncle of Lord Krishna. Kansa was also a dictator, the stories of whose tortures were spread worldwide.
As we already know that Lord Vishnu had incarnated as Krishna in order to bring back the order and re-establish Dharma on earth. Hence, he was supposed to kill all the demonic kings and end their atrocities. So when Jarasandh got the news of his son-in-law having been killed by Krishna, he got enraged and decided to take revenge of Kansa's death.
Jarasandh joined hands with the rulers of Kalinga and Kashi, then known as Kalingraj and Kashiraj, and waged a war against Krishna. However, both the supporting kings were defeated and Jarasandh escaped to save his life. Kashiraj had a son. The son then decided to take revenge of Kashiraj's death. He knew that defeating Krishna would need great powers; hence, he sat for a penance in order to please Lord Shiva.
Within some years of penance, the demon's son succeeded in pleasing Lord Shiva and when Shiva appeared before him, he asked Lord Krishna's death as a wish. Lord Shiva thus gave him a deadly weapon. However, Lord Shiva also mentioned that the weapon should not be used on a person who respects priests.
Kashiraj's son did not know that Lord Krishna highly respected the priests. Thus, unaware of the fact, he attacked Lord Krishna. However, the weapon did not affect Lord Krishna at all and returned to him. In the meantime, Lord Krishna reverted by attacking with the Sudarshan Chakra.
The Sudarshan Chakra thus destroyed Kashi entirely. The place revived again much later when the two rivers Vara and Asi flowed through the region thus giving the name to the place as Varanasi.