Rav Yaakov Kaminetsky in Emes L'Yaakov (Bereishis 34:37):
I was asked by a student how to explain the fact that the Torah
includes descriptions of what happened with Yosef and his brothers.
Isn't this a violation of the prohibition of the laws of lashon harah?
Initially I answered that in truth the prohibition of lashon harah
only applies when mentioning the living. Talking lashon harah about
the dead is permitted according to Torah law and is prohibited only by
an ancient cherem [see Orech Chaim 606:3]. However the prohibition of
the cherem is only against saying false slander (motzi shem rah) and
doesn't apply to negative true statements (lashon harah). However in
truth this question of lashon harah in the Torah simply isn't a
question. That is because Yosef's brothers in fact judged Yosef and
sentenced him to death following the correct legal procedure. They
paskened this way because they thought that that in fact was the law
of the Torah and not because they were perverting the law...
Rabbi Dratch in an essay also echoes this (quoted here, original link does not work):
The Talmud (Brachos 19a) indicates that there is no prohibition of speaking lashon
hara about the dead, either because the dead do not know what is being
said about them or because they do not care what is being said about
them. However, because their legacies are at stake, as well as the
reputations and well-being of their surviving families, and because
they cannot defend themselves, Shulhan Arukh, Orah Hayyim 606:3 cites
a takanat kadmonim (ancient enactment) that prohibits “speaking ill of
the dead.”