The Imams عليه السلام know when they will die and they die voluntarily
Al-Kāfi|Volume 1|Book 4|Chapter 47
8ـ عِدَّةٌ مِنْ أَصْحَابِنَا عَنْ أَحْمَدَ بْنِ مُحَمَّدٍ عَنْ عَلِيِّ بْنِ الْحَكَمِ عَنْ سَيْفِ بْنِ عَمِيرَةَ عَنْ عَبْدِ الْمَلِكِ بْنِ أَعْيَنَ عَنْ ابي جعفر (عَلَيْهِ السَّلام) قَالَ أَنْزَلَ الله تَعَالَى النَّصْرَ عَلَى الْحُسَيْنِ (عَلَيْهِ السَّلام) حَتَّى كَانَ مَا بَيْنَ السَّمَاءِ وَالارْضِ ثُمَّ خُيِّرَ النَّصْرَ أَوْ لِقَاءَ الله فَاخْتَارَ لِقَاءَ الله تَعَالَى.
8. A number of our people has narrated from Ahmad ibn Muhammad from Ali ibn al-Hakam from Sayf ibn ‘Umayra from ‘Abd al-Malik ibn A‘yan from abu Ja‘far عليه السلام who has said the following. “Allah, the Most Holy, the Most High, sent support for Imam al-Husayn عليه السلام up to the fill between the heavens and earth. Then he was let to choose either victory or meeting Allah. He, however, chose the meeting of Allah the Most High.”
- Mirʾāt al-ʿUqūl fī Sharḥ Akhbār Āl al-Rasūl (3/128)
- Ṣaḥīḥ al-Kāfī