Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:3:145

And it is not ˹possible˺ for one to die except by permission of Allah at a decree determined. And whoever desires the reward of this world - We will give him thereof; and whoever desires the reward of the Hereafter - We will give him thereof. And we will reward the grateful.  

It is not for any soul to die, save by the leave of God, by His decree, a prescribed (kitāban, here a verbal noun, that is, God has prescribed this) term, that is to say, ˹a term fixed˺ in time, neither brought forward nor deferred, so why did you retreat ˹in defeat˺? Defeat does not ward off death, nor does standing one’s ground sever life. And whoever desires, by his deeds, the reward of this world, that is, his requital in it, We will give him of it, what has been alloted to him, but he shall have no share in the Hereafter; and whoever desires the reward of the Hereafter, We will give him of it, that is, of its reward; and We will requite the thankful.
القرآن:٣:١٤٥

وَمَا كَانَ لِنَفْسٍ أَنْ تَمُوتَ إِلَّا بِإِذْنِ اللَّهِ كِتَابًا مُؤَجَّلًا ۗ وَمَنْ يُرِدْ ثَوَابَ الدُّنْيَا نُؤْتِهِ مِنْهَا وَمَنْ يُرِدْ ثَوَابَ الْآخِرَةِ نُؤْتِهِ مِنْهَا ۚ وَسَنَجْزِي الشَّاكِرِينَ  

{وما كان لنفس أن تموت إلا بإذن الله} بقضائه {كتابا} مصدر أي: كتب الله ذلك {مؤجَّلا} مؤقتا لا يتقدم ولا يتأخر فلم انهزمتم والهزيمة لا تدفع الموت والثبات لا يقطع الحياة {ومن يُرد} بعمله {ثواب الدنيا} أي جزاءه منها {نؤته منها} ما قسم له ولا حظَّ له في الآخرة {ومن يرد ثواب الآخرة نؤته منها} أي من ثوابها {وسنجري الشاكرين}.