What does a person say if some one passes away?
If you did not know the person and had not even met him, then your comment would naturally need to be confined to, “I am sorry for your loss!” But even if you briefly had some interaction, you might take something from that and mention it in a positive way. I had just such a situation recently. I had met the young man once. He was a pleasant and kind young man. I told them that. They need to hear something positive about the person who they have lost. They need to hear that this person was important in some way. Give it a bit of thought if you had any interaction and find something, however small to say.
The best thing to say is to ask them what they need from you right now. Everyone’s different, so someone may want you to act as normal, others may want a shoulder to cry on, or to leave them alone for a little while to be with their family, and someone else might need help with practical day-to-day stuff (like cooking, or helping to call people or field calls). Your friend might not know what they need from you, or keep changing their mind, but stick with them.
“I’m so sorry for your loss” is exactly right. If it’s a friend, a heartfelt offer of support is always great. Something like, “Is there anything I can do to help?” or “Anything you need, I’m here for you.” (Then really do it, whatever it is.) But don’t push it. If they want to talk about it they will. If not, just be there. It’s easy to put your foot in your mouth trying to be comforting. DON’T say something like “You’ll get over it soon” or “He had a good life.