Literally, 節哀 means to restrain the grief, while 順變 is to accept (or even submit to) what has happened or changed however greatly. So saying 節哀順變 when you hear the bad news or go to a funeral is considered to be very sincere but also serious. I think it sort of feels like saying "my condolences" in English. Sometimes you just need to express you're with them, like:
有什麼我能幫忙的地方,你都可以說。
你需要人陪的話,我隨時都在。
我們一起吃個飯吧!
It would sound nicer and more caring to those who has just lost the beloved ones.