The Messenger of Allah ﷺ used to observe spiritual retreat during the last ten days of Ramadan and the middle ten days. When he passed away, he was observing twenty days of retreat.
حدثنا سليمان بن داود الهاشمي قال حدثنا أبو بكر بن عياش عن أبي حصين عن أبي صالح
كان رسول الله ﷺ يعتكف العشر الأواخر من رمضان والعشر الأواسط فمات حين مات وهو يعتكف عشرين يوما
Its chain of transmission is sahih. Bukhari reported it, 3/62, in the chapter on itikaf, itikaf during the last ten nights, and Muslim, 2/831, no. 5, in the Book of Itikaf, and Abu Dawud, 2466, and Tirmidhi, 790, saying it is hasan sahih, and Ibn Majah, 1769.