Sefer Chofetz Chaim chapter 8 halacha 9

There is a very ancient decree and excommunication on those who speak lashon hara about the dead. Whether the person was a simpleton and all the more so if he was a sage. Insulting and degrading a sage himself is bad all the more so if talking badly about the Torah thoughts he has spoken or written about.

There are many times in Shas and the poskim that they insult each other, and the Chavas Yair explains many if the examples in Shas of why it’s not lashon hara or insulting each other. For example, Rav Sheshes told Rav it sounds like you were just dozing off and sleeping. He wasn’t saying this as an insult, on the contrary it was a praise because normally Rav was very sharp and it must have been that if he missed something he must have fallen asleep. Another example is when Rebbe said to Levi that it seems you have no brains in your skull. Now, Levi was a student of Rebbe and Rebbe was rebuking his student to work and think harder. The Rambam and Shulchan Aruch (Yoreh Deah 246:11) learn from here that a Rebbe should speak harshly to his students if he is feeling it will encourage and inspire them to work harder, not out of anger or haughtiness, but rather a drive to make sure they toughen up if it looks like they are being lazy.