Mishkat al-Masabih 1559
وَعَنْ عَبْدِ اللَّهِ بْنِ عَمْرٍو قَالَ: قَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسلم: إِن الْعَبْدَ إِذَا كَانَ عَلَى طَرِيقَةٍ حَسَنَةٍ مِنَ الْعِبَادَةِ ثُمَّ مَرِضَ قِيلَ لِلْمَلَكِ الْمُوَكَّلِ بِهِ: اكْتُبْ لَهُ مِثْلَ عَمَلِهِ إِذَا كَانَ طَلِيقًا حَتَّى أطلقهُ أَو أكفته إِلَيّ
From ʿAbdullah ibn ʿAmr, who said: The Messenger of Allah ﷺ said: "When the servant is following a good way of worship and then falls ill, it is said to the angel appointed over him: 'Write for him the like of his deeds when he was free, until I release him or take him to Myself.'"