I have had a lot of experience with funerals and people in mourning, both as one whose kin have died and in ministering to the bereaved. Here is a short course in what to say to the next of kin of the deceased.
What not to say
Do not attempt to explain the death. Comments such as, "This is all part of God's plan," or "There is some purpose served here that we don't understand" are not helpful. Just skip them. Grieving parents, widows or widowers are not looking for cosmic wisdom or theology. No matter how helpful you think such things are, or how intensely you believe them, they do not help and can be very hurtful.
Do not minimize the impact of the death. Deaths of loved ones are consequential, and must be regarded as such. A woman I knew had to bury her three-day-old baby girl. A woman of her church told her, "At least it wasn't a boy." In the recent death of my elderly and long-term ill mother-in-law, several people said to my wife and me, "At least she isn't suffering anymore." I have heard family members say that, but others should not. That's their call, not yours. These kinds of comments are not helpful.
Do not talk about the unfairness of life or make the deceased and the family a victim of circumstances. Comments such as, "I don't see why the doctors could not have done more," or "Your wife was such a good woman, I don't see why she had to die" or the like harm rather than help. The deaths of loved ones create chaos in the mental and emotional states of the families. Often, they wonder whether they could have done something more to save the deceased. Don't say anything that could reinforce these feelings.
What to say
Express sympathy and offer support. Be a friend. Be brief and sincere. Here is a template you can use either verbally or in writing a sympathy card:
I am saddened to hear of your loss. Please be assured that my prayers are with you. I know these days are difficult for you. You have many friends who will support you and who are eager to give you aid and comfort. We pray that you will be strengthened through God's grace, and come to find rest and peace. Sincerely, [name].It is not inappropriate to offer, "If there is anything we can do, let us know," but not many next of kin will let you know. If you truly want to offer more than moral support, just do it. Offer to take their car to be washed before the funeral. Offer to do their laundry or house sit or visit to answer the phone. Be imaginative in discerning what routine tasks you can perform for the bereaved; those are the tasks that tend to be left undone. Never force yourself on the bereaved, of course, but usually a doer is gratefully welcomed while a mere promiser is forgotten.
If the death was tragic (that is, premature, suicidal or violent) then you should understand that support will be needed for many weeks, not just a few days. The level of support required will decrease, but do not expect that after only a week or so the bereavement will just end and the bereaved will get on with life. "Getting over it" is something that may never happen for the families of those who died tragically. Parents who lose children, for example, never get over it emotionally although after a time their routines may appear normal. But they always grieve, even after decades.
Anniversary dates can be particularly difficult. For those who lose spouses, the next Valentine's Day can be very difficult. A card or bouquet on that day will be very helpful. A phone call on wedding anniversaries or birthdays of the deceased will be much appreciated.