When someone has lost a loved one, then it is best not to tell them you’ll pray for them or their loved one unless you are sure they would welcome the prayers.
Many Protestants do not believe their deceased loved ones need prayer because they do not believe in Purgatory.
Many unbelievers do not want prayers of any kind.
In addition, even someone who believes may have a bad reaction to being offered a prayer because they are in grief and they may be upset at God or thinking “what good do prayers do” etc.
So be careful about offering a prayer unless you know the person will welcome it. For example, if they’ve asked everyone to pray for them, or you know they’re a devout Catholic, they’ll probably be fine with you offering the prayer.
For those who you’re not sure will welcome the prayer, simply pray for them and their loved one, and don’t tell them you did it. “Stealth prayers”. It is perfectly okay for you to pray for anyone, any time, and you don’t need to get their permission to pray.