Allah (swt) says:
وَ اِذَا الۡمَوۡءٗدَۃُ سُئِلَتۡ ۪ۙ بِاَیِّ ذَنۡۢبٍ قُتِلَتۡ ۚ
Wa ‘izal - maw - ‘uudatu su’ilat; Bi - ‘ayyi zambin - qutilat?
“Indeed, those who like that immorality should be spread [or publicized] among those who have believed will have a painful punishment in this world and the Hereafter. And Allah knows and you do not know.” (An-Noor, 24: 20)
In a Hadith Hazrat Muhammad (pbuh) has said:
“He who sees something which should be kept hidden and conceals it will be like one who has brought to life a girl buried alive.” (Abu Dawud, Kanz al-’Ummal, Tabarani)
This Sahih Hadith teaches us that he who finds a defect/ weakness, whether physical or moral in a Muslim and who conceals it, that is to say, he does not spread it among the people, but rather keeps the matter a secret, then he shall have a reward comparable to the one who saves a girl buried alive from her grave, for this practice was widespread among the Arabs at the time of the Jahiliyya (ignorance, before the advent of Islam), as well as among the pagans and the ignorant ones before the advent of the Holy Prophet (pbuh). We need to advise people to improve their conduct (to atone for their wrongdoings) but it is illegal for us to reveal their flaws to those who are not concerned (with that matter).