A person is suffering from AIDS and the doctors have said that he only has a short time to live. What is the ruling on his repentance during this time?
Praise be to Allah.
He must hasten to repent, even if it is at the time of death because the door of repentance is always open so long as he is of sound mind. He must hasten to repent and beware of sin, even if they have told him that the time he has left to live is short because life spans are in the hand of Allaah. The doctors may be mistaken in their thinking, and he may live for a long time. Whatever the case, he must hasten to repent and be sincere in doing so, so that Allaah will accept his repentance. Allaah says (interpretation of the meaning):
“And all of you beg Allaah to forgive you all, O believers, that you may be successful” [al-Noor 24:31]
“And verily, I am indeed forgiving to him who repents, believes (in My Oneness, and associates none in worship with Me) and does righteous good deeds, and then remains constant in doing them (till his death)” [Ta-Ha 20:82]
And the Prophet (peace and blessings of Allaah be upon him) said:
“Allaah will accept a person’s repentance so long as the death rattle has not reached his throat” i.e., up until the time when the dying person loses consciousness. And Allah is the One Whose help we seek.
And Allah knows best
Source: Islamic QA