When we learned the parsha our rav explained that there are different reasons for a house getting tzora'as. The reason of lashon hara is as specified by the Rambam shown in the question is only one of the possibilities. Another possibility is that it comes to punish stinginess
See link
In identifying the reason that Tzoraas came upon a person’s house, the
Talmud Yoma 11b centers on the words, “The person to whom the house belongs,”
and explains that Tzoraas of the house comes upon a person who is
stingy. Instead of being kindhearted and helpful, this man lived with
the motto that his house belonged to him alone. Over the years, when
neighbors asked to borrow things, he would answer, “I don’t have
that.” Now with his contents strewn on his front lawn it became clear
to all that he did have the items in question.
Unfortunately, when I try to follow the link to the quote, above, I do not get to the correct page. I will add another quote One-of-a-Kind Punishment
by Jesse Dunietz
At the tail end of the numerous laws of Tzaraat specified by Parshiot
Tazria and Metzora, the Torah discusses the topic of Tzaraat on a
house. The Torah introduces this topic by saying, “Ki Tavo’u El Eretz
Kena’an…Venatati Nega Tzaraat Beveit Eretz Achuzatchem,” “When you
come to the Land of Canaan…I will put an affliction of Tzaraat in the
house of the Land of your inheritance” (14:34). Rashi on this Pasuk
quotes the famous Midrash (Vayikra Rabbah 14:7) that when the owner of
a Tzaraat-stricken house would tear down his home, as per the Torah’s
instructions, he would find golden treasures. These riches had been
left by the previous Emori inhabitants of the houses, who, fearing
Bnei Yisrael’s impending invasion, had hidden their valuables in the
walls when Bnei Yisrael were wandering in the Midbar. Famous though it
may be, this is quite a puzzling comment; after all, Chazal in a
number of places clearly associate Tzaraat with major sins,
particularly Lashon Hara. What could possibly lead Rashi (and the
Midrash he quotes) to believe that Tzaraat on a house signifies
something positive? Many commentators (Mizrachi, Siftei Chachamim,
Yefei Einayim, Re’eim, and others) point to the difference between the
Torah’s language in this Pasuk and that which it uses to introduce the
other types of Tzaraat afflictions. In our Pasuk, Hashem specifically
says “Venatati,” “and I will give,” a word with an active and positive
connotation. In contrast, all the other Pesukim that describe the
presence of Tzaraat, such as 13:2, 13:42, and 13:47, simply use
“Yihyeh” or “Tihyeh,” “it shall be.” The Pasuk about houses is thus
the only one with the positive undertones. Some commentators, based on
the continuation of the Midrash, also bring support from the
parallelism between our Pasuk and a promise Hashem later makes in
Devarim (6:10). There we are told, “When He will bring you to the Land
which He swore…to give you, and houses full of all good things….” Both
of these Pesukim start by mentioning entrance into the Land, continue
with a reference to Hashem’s commitment to give it to us, and conclude
by discussing the houses of the Land. The fact that “houses full of
all good things” in Devarim corresponds to our Pasuk’s reference to
Tzaraat implies that the Tzaraat affliction on houses is actually a
fulfillment of the promise in Devarim. This explanation provides a
compelling textual basis for the assertion of Rashi and the Midrash
that house-Tzaraat is, at least to some extent, a positive experience.
However, this still leaves us with a philosophical conundrum: how
could the phenomenon that carries so many negative associations, and
which the Torah constantly calls a “Nega,” an affliction, have such a
positive aspect to it? Furthermore, the Gemara states explicitly in
several places (Yoma 11 and Arachin 16) that Tzaraat afflicts houses
because of the owner’s stinginess, particularly because of denying
that one has the means to aid others. This, according to the Gemara,
is why the owner of the house must clear his possessions out of his
house – he is being forced to publicly display the true extent of his
means, contradicting his stingy claims. According to these Gemaras,
Tzaraat on a house, like the other forms of Tzaraat, is clearly a
punishment for inappropriate behavior. How can we reconcile this with
the positive light in which Rashi seems to view this phenomenon? Rav
Y. Eiger suggests that this is a form of punishment through Chesed. He
brings the analogy of a king who has been insulted by a lowly peasant.
Such a king may decide, rather than punishing the peasant harshly, to
elevate him to a high position and give him gifts. Upon comprehending
the kindness and greatness of the man whom he so disrespected and
degraded, the peasant will become ashamed of the foolishness of his
actions. Similarly, Hashem acts kindly and positively towards the
homeowner afflicted with Tzaraat as part of his correction process –
He causes the sinner to understand what and Whom he spurned by
sinning, thus paving the way for shame, regret, and repentance. The
Tzaraat is a punishment of sorts, but punishment through Chesed. Rav
Eiger’s explanation, though quite clever, still leaves one gaping
hole. Why is it specifically the man who has Tzaraat, and particularly
Tzaraat on his house, who is given such treatment? We do not say, for
example, that one who violates Shabbat should be rewarded for such
behavior so that he will feel shame and repent! I would like to
suggest (with thanks to my father for his help with this idea) that
this model of reward combined with punishment is aptly suited to the
particular sin that causes Tzaraat on a house. As we mentioned before,
the Gemara states that such Tzaraat is a result of stinginess and
unwillingness to share one’s possessions. To counteract this attitude,
Hashem drives home to the offender the message of wholehearted
generosity. In the midst of forcing this man to clear out and tear
down his house, Hashem still showers him with gifts; even while
expressing His strong disapproval of the man’s actions, Hashem’s
generosity does not cease. To receive such a gift in the middle of
what he knows to be a punishment forces the owner of the house to
contemplate the concept of generosity. If Hashem is willing to grant
such gifts to a lowly sinner such as himself, how much more willing
should he be to lend and give to his worthy neighbors! Thus, because
of the context in which he is given these “golden treasures” hidden in
his walls, it is particularly the sufferer of house-Tzaraat who will
be compelled to feel shame about what he did, and hopefully to reshape
his mode of generosity and giving to fit the example that Hashem’s
gift to him provides. Finally, Rabbi Chaim Jachter has suggested that
we might understand Rashi’s approach to house-Tzaraat in light of a
general phenomenon in Rashi’s commentary to the Chumash. It appears
that Rashi hardly ever misses an opportunity to heap praise on the
Jewish people. Even passages in the Chumash that would on the surface
appear to be critical of Am Yisrael are often interpreted in a manner
that reflects Hashem’s love for His nation. Perhaps Rashi’s positive
spin on house-Tzaraat is one of the many expressions of the manner in
which Rashi lifts the spirit and pride of Am Yisrael to empower us to
resist the humiliations that many of our critics both past and present
relentlessly heap upon us.
Thus the reason of finding the treasure is a third reason in order to both give a person a warning and to reward him because he does learn the lesson:
Rabbi Moshe Feinstein explains that although the plague came to
benefit the house owner with treasure, that objective was possible to
achieve without going through the ordeal of destroying their house.
The tzoraas experience was demanding and unpleasant, to alert the
recipient of his wrongdoing and need for change. The plague worked to
achieve both punishment and reward.
Rabbi Avigdor Miller further elaborates that the Creator of the
World, in His infinite wisdom, has a master plan that our finite human
minds cannot fathom. This plan will materialize, and cannot be stopped
or frustrated by our decisions and actions. Certain events are
destined to occur regardless of our actions, but the sequence or
details of the events may be manipulated to teach us a Divine lesson.