Rulings on offering condolences
Question

What is meant by offering condolences, how is it done, and what is the time for that?
Praise be to Allah.Offering condolences means comforting the one who has been stricken by calamity and giving him strength to bear what has befallen him.
What is meant by the one who has been stricken by calamity is the one who has been affected by loss of a loved one or relative, or loss of wealth. So condolences for bereavement may be offered to anyone who has been bereaved, whether the bereaved is one of his family, or a friend or neighbour.
Offering condolences means comforting the one who has been stricken by calamity and assuaging his grief. The best way to offer condolences is that which is proven from the Prophet (blessings and peace of Allah be upon him), that when a messenger came from one of his daughters asking him to come to her son who was dying, the Prophet (blessings and peace of Allah be upon him) said: “Go back to her and tell her that to Allah belongs what He has taken, and to Him belongs what He has given, and everything has an appointed time with Him. So tell her to be patient and seek reward with Allah.” Narrated by al-Bukhaari (1204).
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) was asked how condolences are to be offered.
He replied: The best way to offer condolences is in the words with which the Prophet (blessings and peace of Allah be upon him) offered condolences to one of his daughters, when she sent a messenger to him calling him to come, when a son or daughter of hers was dying. The Prophet (blessings and peace of Allah be upon him) said to this messenger: “Tell her to be patient and seek reward with Allah, for to Allah belongs what He has taken, to Him belongs what He has left, and everything has an appointed time with Him.”
With regard to what people commonly say: “May Allah increase your reward, may Allah console you, may Allah forgive your deceased loved one,” these are words that were favoured by some of the scholars, but what is narrated in the Sunnah is more appropriate and is better."(Majmoo‘ Fataawa Ibn ‘Uthaymeen (17/339).
It is permissible to offer condolences after the burial and before. So if someone offers condolences to the family of the deceased before the burial, washing or funeral prayer, there is nothing wrong with that and it serves the purpose. If he offers condolences after the burial, there is nothing wrong with that.
Shaykh Ibn ‘Uthaymeen was asked: What is the right time to offer condolences?
He replied: The time for offering condolences is from the moment when the deceased passes away or the calamity occurs, if condolences are being offered for something other than a death, until such time as the calamity has faded from the mind of the one who was stricken, because the purpose of offering condolences is not like congratulations or greetings; rather the purpose is to give the one who has been affected strength to bear this calamity with patience and advise him to seek reward with Allah."(Majmoo‘ Fataawa Ibn ‘Uthaymeen 17/240).
And Allah knows best.