Though I can’t say for sure that this is accepted as definitive Church teaching,* St. Ignatius of Loyola gave us a very helpful way to consider the act of gossiping—i.e., one that may strongly discourage us from it:
“Nothing should be said to lessen the good name of another, or to complain about him. For if I reveal the hidden mortal sin of another, I sin mortally; if I reveal a hidden venial sin, I sin venially; if his defect, I manifest my own” (“General Examination of Conscience: Words,” q. in Hardon, S. J., The Treasury of Catholic Wisdom, Kindle edition).
In other words, if I were to say that someone else has such and such defect or has committed such and such sin, I simultaneously demonstrate myself being defective or sinful by engaging in one of those things right before the eyes of whomever I’m addressing. Rather than just saying “look how bad or stupid so-&-so is,” I’m doing significantly more to show (and prove) “look how bad and stupid I am!” For while I’m saying that someone else supposedly did something wrong, I myself am doing something wrong and am injuring my soul for it—right in front of the person I’m talking to.
This isn’t to say that there is never “objectively valid reason” for revealing the faults of another (Catechism of the Catholic Church, 2477—see this source also for the last sentence of the preceding paragraph). Sometimes there is valid reason to do so. Ignatius (q. from the same source as above) lists a couple of these reasons:
“If, however, my intention is good, there are two ways in which it is permissible to speak of the sin or fault of another:
“1. When a sin is public, as in the case of a woman openly leading a shameless life, or of a sentence passed in court, or of a commonly known error that infests the minds of those with whom we live.
“2. When a hidden sin is revealed to someone with the intention that he help the one who is in sin to rise from his state. But then there must be some grounds or probable reasons for believing that he will be able to help him.”
Though the implication is that this is an exhaustive list, I would beg to differ. For instance, it would seem to me that revealing the sins of another would be permissible in instances where shared knowledge of these sins could save others from future and/or continued harm from those sins or sinful tendencies, or where the one whose sins were revealed was given sufficient anonymity.
*In saying this, I’m referring especially to where Ignatius says that it is a mortal sin to reveal the hidden mortal sin of another. It’s definitely sinful to reveal such a thing, I just do not know if/where it’s held to be mortally sinful by the Church. Perhaps it is and I just haven’t come across it. Regardless, this seems like a valuable way to think of it: even if it’s not mortally sinful to reveal the hidden mortal sin of another, if we treat it as if it were, we’ll be that much less likely to do it.