The Messenger of Allah ﷺ said three times, "May Allah have mercy on a person who speaks and gains, or remains silent and stays safe."
قال رسول الله ﷺ ثلاث مرار: رحم الله امرءا تكلم فغنم، أو سكت فسلم.
No references are available.
Bayhaqi related it in Shu'ab al-Iman (4589) via Ismail bin Ayyash, who said, Umara bin Ghaziya Ansari told us, from Ibn Shubruma, that he heard him narrating from Thabit, from Anas bin Malik, who said, and then he mentioned it.Ismail bin Ayyash is the Hims scholar who mixes up his narrations from non-Levantine narrators, and this is one such case, since Umara bin Ghaziya Ansari is from Madinah. However, it is strengthened by the mursal narration of Hasan Basri, which is what Ibn Abu Dunya related in al-Samt (41) from Ubaydullah bin Umar bin Hafs bin Asim, who said, Hazm bin Abu Hazm told us, I heard Hasan say, it was mentioned to us that the Prophet of Allah ﷺ said, and then a similar hadith is given, its narrators being trustworthy.Through these two chains together, the hadith rises to the level of hasan.As for his saying, "He spoke and gained, or stayed silent and was safe," it means, he spoke good words and thereby gained reward and recompense, or he refrained from speaking evil and was thereby safe from sin and punishment.