As-Salaam alaikum,
Malik bin Anas reported from Yahya bin Sa'eed who quoted it from Sa'eed bin al-Musayyab, who quoted it in turn from Omar bin al-Khattab, may Allah be pleased with them all, who reported that the Prophet, Sallallahu alaihi Wasallam, said:--

"Always remember the terminator of pleasures", so we asked: "What is the
terminator of pleasures, O Messenger of Allah?"
He replied: "It is death."

In another Hadith, on the authority of Anas, may Allah be pleased with him, the Prophet alaihis-salaat was-salaam, said:--

"Remember death recurrently because so doing wipes out sins
and makes you disregard this worldly life."

So, if one is in distress, remembering death will alleviate his or her pain because it (death) is harder than any other misery. And if he is in a state of happiness and abundance, remembering death protects him/her from rolling in the pleasures of life and counting on it... as he/she knows he will part with it one day.