Question:

Why did the prophet do itikaaf for 20 days in his last year and repeat the Quran twice in his last year if he didn’t know when he would die?

Answer:

عَنْ أُبَىِّ بْنِ كَعْبٍ، أَنَّ النَّبِيَّ ـ صلى الله عليه وسلم ـ كَانَ يَعْتَكِفُ الْعَشْرَ الأَوَاخِرَ مِنْ رَمَضَانَ فَسَافَرَ عَامًا فَلَمَّا كَانَ مِنَ الْعَامِ الْمُقْبِلِ اعْتَكَفَ عِشْرِينَ يَوْمًا ‏.‏

It was narrated from Ubayy bin Ka’b that:
The Prophet (ﷺ) used to spend the last ten days of Ramadan in I’tikaf. One year he was traveling, so the following year he spent twenty days in I’tikaf.

Reported by Ibn Maajah and others.

 إِذَا أَرَادَ اللَّهُ بِعَبْدٍ خَيْرًا اسْتَعْمَلَهُ ” . قِيلَ : يَا رَسُولَ اللَّهِ ، وَكَيْفَ يَسْتَعْمِلُهُ ؟ قَالَ : ” يَهْدِيهِ لِعَمَلٍ صَالِحٍ قَبْلَ مَوْتِهِ ” .

If Allah wants the good of a servant He employs him before he dies.
He was asked, “How would Allah employ him, O Allah’s Messenger!” 
He said:
He guides him to performing righteous deeds before his death.
Reported by al-Imaam Ahmad and others.

Mentioned by

AbdulFattaah Bin Uthman
Abu Fajr