Answer: The Gemara (Bava Metzia 102a) writes that one renting a house from a Jewish person shouldn’t remove their mezuzos upon leaving (See Rambam, Mezuza 5:11; Shulchan Aruch YD 291:2). Tosafos (Shabbos 22a) explains that aside from serving to remind us of Hashem, mezuzos also protect the house from harm. The Tur (YD 285:2) stresses, however, that this isn’t the reason for this mitzva and one shouldn’t affix one’s mezuzos with this in mind (See Aruch Hashulchan YD 285:3).
The Rema (YD 291:2) points out that the old tenant can charge the new tenant or owner for their mezuzos. R’ Ovadia Yosef (Yabia Omer YD 3:18) writes, therefore, that even if one knows that the new tenant will be affixing their own mezuzos, the old ones must stay up until they affix their new ones. One who has expensive mezuzos and is concerned that they won’t be paid for them properly may remove them to have them checked and replace them with cheaper ones.
R’ Moshe Feinstein (Igros Moshe YD 4:44) quotes R’ Yosef Eliyahu Henkin who held that if the house is going to anyway be repainted and one will remove them to protect them, then one can take them with to affix in their new home (See Aruch Hashulchan YD 291:3).
In conclusion, it is important that one doesn’t remove one’s mezuzos upon leaving one’s house if another Jewish person is moving in. If the house is going to be repainted in the meantime and they will need to be removed, one may take them with them for their new home if necessary.