If a city has been led astray into idolatry, there is a positive mitzvah to burn it and everything in it. This law applies to a city that has been deemed an “ir hanidachas,” meaning that they meet certain conditions. For example, they have to have been led astray by at least two deceivers as per Deuteronomy 13:14. Those deceivers have to be from the same Tribe as the city they misled (ibid.) and the majority of the population has to be so misled, up to half the Tribe. A city must have at least 100 residents even to be up for consideration. There are many more conditions for a city to be judged an ir hanidachas, enumerated in Talmud Sanhedrin 111b.
If a city is deemed an ir hanidachas, it and everything in it must be burned. (If a city fails to be deemed an ir hanidachas, the idolaters are liable to the penalty of stoning and their heirs inherit their property.) Jerusalem and cities of refuge are ineligible to be deemed cities led astray.
The reason for this mitzvah is that the ir hanidachas is a cancer. It is so thoroughly corrupt that it must be altogether wiped out. It would not do to have other residents moving in or artifacts from the city in circulation. Its legacy must be destroyed.
This mitzvah only applies at a time when the Jews reside in their land. It is discussed in the Talmud in the tractate Sanhedrin on page 111b. It is codified the Mishneh Torah in the fourth chapter of Hilchos Avodas Kochavim. This mitzvah is #184 of the 248 positive mitzvos in the Rambam’s Sefer HaMitzvos.