If a person demolishes his home for whatever reason, he must first remove all the Mezuzot so as to prevent their destruction and degradation. Likewise, when a person rents his house or apartment to a gentile, he must, as the Shulchan Aruch writes, first remove all the Mezuzot. (Shulchan Aruch, Yore Dea 291:2)
When a person rents his home to another Jew, the obligation of Mezuza falls upon the renter, and not the landlord (ibid). There is considerable discussion among the authorities as to when this obligation takes effect. This depends on the terms of the deal. If one is renting for no specific time then he (the renter) is exempt for 30 days. He may place the Mezuzah before 30 days but only without a blessing. After 30 days, he may make a blessing. However, if one rents the dwelling for a long period of time (for example 6 months – 1 year) then the renter must put up the Mezuzot immediately, but without a Beracha. In Israel, however, a renter must put up Mezuzot immediately with a Beracha. (Halichot Olam, Helek 8, page 304.)
If one bought a house, he must immediately without delay put up Mezuzot with a Beracha.