The ruling on Condolences and how they are to be given
Question :
Is specifying three days for condolences for the family of the deceased considered from the innovated matters, and are there any condolences to be given for the infant, the elderly person and the terminally ill person after their death?
Answer:
Giving condolences is a Sunnah due to what it contains of showing support for the one stricken with a calamity, and supplicating for good for him. There is no difference in that as to whether the deceased is a child or an adult. There is no specific wording for it. Rather, the Muslim consoles his brother by whatever is easy of appropriate words, for example saying: "May Allâh make your condolences good and grant you strength in your calamity and forgive your deceased." This is if the deceased was a Muslim. However, if the deceased was a disbeliever, supplications should not be made for him. Condolences are only given to his Muslim relatives with words similar to what has been mentioned (ie., condolences to non-Muslims should not include such supplication for them).
There is no specified time for condolences, nor any specified days. Rather, it is legislated from the time of the death of the deceased. It may be before the funeral prayer and after it, and before the burial and after it. It is better to make haste in giving the condolences early on in the case of severe calamity. It is also allowed to give condolences after three days from the passing of the deceased, as there is no evidence that proves any restriction.
Source:
Ash-Shaykh Ibn Baz
Fatawa Islamiyah, Vol. 3 Pages 96-97