To someone who lost the loved one.
To the one who passed away (R.I.P)
In Japanese, an equivalent to “I am so sorry for your loss.” does not exist. Please do not say “ごめんなさい(gomennasai)” nor “すみません(sumimasen)” unless the cause of death was you.
“ごめんなさい(gomennasai)” or “すみません(sumimasen)” as “I am sorry” in Japanese are only used if it is your fault.
In that situation, not to say anything other than those two sentences I mentioned are better. The sadness cannot heal by a word, you cannot take their pain away. Only the time can heal it. Not to say anything, but stand by them is the better way in Japan. The family are very busy to taking care of the funeral a few days and no time to mourn. Texting or calling to tell what you feel is important but also to give them time to mourn quietly is also important.