The Imams عليه السلام know when they will die and they die voluntarily
Al-Kāfi|Volume 1|Book 4|Chapter 47
5ـ عَلِيُّ بْنُ إِبْرَاهِيمَ عَنْ مُحَمَّدِ بْنِ عِيسَى عَنْ بَعْضِ أَصْحَابِنَا عَنْ أَبِي الْحَسَنِ مُوسَى (عَلَيْهِ السَّلام) قَالَ إِنَّ الله عَزَّ وَجَلَّ غَضِبَ عَلَى الشِّيعَةِ فَخَيَّرَنِي نَفْسِي أَوْ هُمْ فَوَقَيْتُهُمْ وَالله بِنَفْسِي.
5. Ali ibn Ibrahim has narrated from Muhammad ibn ‘Isa from some of our people from abu al-Hassan Musa عليه السلام who has said the following. “Allah, the Most Holy, the Most High expressed anger at the Shi‘a. He, therefore, let me choose either myself or them (to receive protection). I swear by Allah, that I protected them with my own soul.”
- Mirʾāt al-ʿUqūl fī Sharḥ Akhbār Āl al-Rasūl (3/126)
- Ṣaḥīḥ al-Kāfī