The finest wording that has been given for offering condolences is that chosen by the Messenger of Allah ﷺ when a messenger from one of his daughters came to him, saying that she had a child at the point of death. The Messenger of Allah ﷺ said to her: “To Allah belongs what He takes, and to Him belongs what He gives; and everything with Him has an appointed term. Tell her to be patient and to seek the reward.” (1)
He said, “To Allah belongs what He takes, and to Him belongs what He gives,” meaning: the child whose loss has afflicted you does not belong to you; rather, he belongs to Allah. The father whose loss has afflicted you belongs to Allah; he does not belong to you.
And he said, “Everything with Him has an appointed term,” meaning, a specified term. Allah the Exalted says: “When their appointed time comes, they can neither delay it by a single moment nor bring it forward.” [Al-A'raf: 34] What has been decreed must inevitably occur, and it cannot change from what it was decreed to be in any way. Thus, do not regretfully say, “If only I had not done such-and-such,” and so on.
He said, “Tell her to be patient,” meaning, patient in the face of this calamity.
Patience, true to its name, is bitter in taste,
Yet its outcome is sweeter than honey.
Patience is difficult, but its consequences are praiseworthy.
He said, “and to seek the reward,” meaning, that she should seek her reward from Allah, for Allah says: “Indeed, those who are patient will be given their reward without measure.” [Az-Zumar: 10]
His statement, “offering condolences to the afflicted person”: he did not say, “offering condolences to the relative,” so that the ruling may apply consistently in both directions. Thus, everyone afflicted by a loss should be consoled, even if he is a distant relative; and whoever has not been afflicted should not be consoled, even if he is a close relative. Whoever has been afflicted, console him; and whoever has not been afflicted, do not console him.