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:2:94

Say, ˹O Muhammad˺, "If the home of the Hereafter with Allah is for you alone and not the ˹other˺ people, then wish for death, if you should be truthful.  

Say, to them: ‘If the Abode of the Hereafter, that is, Paradise, with God is purely yours, that is, exclusively, and not for other people, as you allege, then long for death — if you speak truly’ (here both conditionals are connected to the verb tamannū, ‘long for’, so that the first is dependent upon the second, in other words, ‘If you speak truly when you claim that it is yours, then you will naturally incline to what is yours, and since the path to it is death, long for it ˹death˺’).
القرآن:٢:٩٤

قُلْ إِنْ كَانَتْ لَكُمُ الدَّارُ الْآخِرَةُ عِنْدَ اللَّهِ خَالِصَةً مِنْ دُونِ النَّاسِ فَتَمَنَّوُا الْمَوْتَ إِنْ كُنْتُمْ صَادِقِينَ  

{قل} لهم {إن كانت لكم الدار الآخرة} أي الجنة {عند الله خالصة} خاصة {من دون الناس} كما زعمتم {فتمنوا الموت إن كنتم صادقين} تعلق بتمنوا الشرطان على أن الأول قيد في الثاني أي إن صدقتم في زعمكم أنها لكم ومن كانت له يؤثرها والموصل إليها الموت فتمنوه.

See similar narrations below:

Collected by Qurʾān
quran:62:6

Say, "O you who are Jews, if you claim that you are allies of Allah, excluding the ˹other˺ people, then wish for death, if you should be truthful."  

Say: ‘O you of Jewry, if you claim that you are the ˹favoured˺ friends of God, to the exclusion of other people, then long for death, if you are truthful’ (in kuntum sādiqīna is semantically connected to tamannū, ‘long for’; as for the two conditions, the first is dependent on the second, that is to say, if you are truthful in your claim that you are the ˹favoured˺ friends of God, and given that ˹such˺ a friend would prefer the Hereafter ˹to this world˺ and that it ˹the Hereafter˺ begins at death, then long for it).
القرآن:٦٢:٦

قُلْ يَا أَيُّهَا الَّذِينَ هَادُوا إِنْ زَعَمْتُمْ أَنَّكُمْ أَوْلِيَاءُ لِلَّهِ مِنْ دُونِ النَّاسِ فَتَمَنَّوُا الْمَوْتَ إِنْ كُنْتُمْ صَادِقِينَ  

{قل يا أيها الذين هادوا إن زعمتم أنكم أولياء لله من دون الناس فتمنوا الموت إن كنتم صادقين} تعلق بتمنوا الشرطان على أن الأول قيد في الثاني، أي إن صدقتم في زعمكم أنكم أولياء لله، والولي يؤثر الآخرة ومبدؤها الموت فتمنوه.