The Prophet (may Allah's peace and blessings be upon him) is urging Muslims not to die except while having good expectations of Allah by making their hope for Allah's mercy and pardon outweigh when being in a state of moribundity. Because fear is required to improve deeds; however, this is not a state for offering deeds. Hence, the prevalence of hope is required here.
Lessons
Keenness of the Prophet (may Allah's peace and blessings be upon him) on guiding his Ummah and his deep compassion for them in all of his states; even in his final illness, he was advising his Ummah and guiding them to the means of salvation.
At-Tībi said: Perform good deeds now so that you have good expectations of Allah at the time of death, as those whose deeds are evil have ill expectations of Allah at the time of death.
The slave's most perfect state is having a moderate level of hope and fear along with the prevalence of love, as love is the mount, whereas hope is the conductor, fear is the driver, and Allah is the One Who helps one reach his destination through His favor and generosity.
Anyone who is near a dying person should help him have strong hope and good expectations of Allah, as in this Hadīth, the Prophet (may Allah's peace and blessings be upon him) said this three days before his death.
Explanation in Arabic
حَثَّ النبيُّ صلى الله عليه وسلم المسلمَ بأن لا يموت إلا وهو يُحسِنُ الظنَّ بالله بتَغْلِيْبِه جانبَ الرجاء عند الاحتضار بأن الله يرحمُه ويعفو عنه، لأن الخوف مطلوب لتحسين العمل، وتلك الحالة ليست حالة الأعمال، فالمطلوب فيها غَلَبَةُ الرجاء.
حِرْص النبيِّ صلى الله عليه وسلم على إرشاد أمته، وشدة رأفته بها في جميع أحواله؛ حتى في مرض موته ينصح أمتَه ويدلُّها على مسالك النجاة.
قال الطيبي: أحسنوا أعمالكم الآن حتى يَحْسُنَ ظنُّكم بالله عند الموت، فإنَّ مَن ساء عملُه قبل الموت يَسوء ظنُّه عند الموت.
أكمل الأَحْوال للعبد اعْتدال الرَّجاء والخوف، وغلبةُ الحب؛ فالمحبَّة هي المرْكَبُ، والرَّجاء حادٍ، والخوف سائق، والله الموصل بمنِّه وكرمه.
ينبغي على من كان قريبًا ممن حَضَرَه الموت أنْ يُغَلِّب عنده جانب الرجاء وحسن الظن بالله، ففي هذا الحديث أنه صلى الله عليه وسلم قال ذلك قبل أن يموت بثلاث.
وعن جابر بن عبد الله، رضي الله عنهما ، أنه سمع النبي، صلى الله عليه وسلم، قبل موته بثلاثة أيام يقول : لا يموتن أحدكم إلا وهو يحسن الظن بالله عز وجل" ((رواه مسلم)).