Of no effect is the repentance of those who continue to do evil, until death faces one of them, and he says, “Now have I repented indeed;” nor of those who die rejecting Faith: for them have We prepared a punishment most grievous.
According to Anwar ul Bayan,
Repentance (Taubah) Not Accepted at the Time Of Death
Taubah is not accepted from those people who continue to commit sins till they finally reach their dying moments. Neither is it accepted from those who die as disbelievers. (kuffar).
When death presents itself before a person, he witnesses the realm of the unseen world. At that moment, his repentance will never be accepted. The Holy Prophet (S) said, “Verily Allah accepts the repentance of his slave as long as he is not in the throes of death” [Ahmad]. This occurs when the soul is about to be removed.
At this time, when the person can see the angels and feel the pangs of death grip hold of him, neither the repentance (Taubah) of a Muslim nor that of a disbeliever are accepted. At this point, the Belief of a disbeliever is also not accepted since Belief (Iman) of the unseen is required of a person. Once the domain of the unseen becomes visible to the dying person, the unseen will now be considered to be ‘seen’. Belief (Iman) on something that is ‘seen’ is not adequate.
Allah accepts the repentance (Taubah and Belief (Iman) of people at any time before they reach the throes of death. The repentance (Taubah) should be sincere and, should the person sin after repenting, he should not hesitate to repent again, for Allah is Most Forgiving, Most Merciful.
Madani, Muhammad. Anwar ul Bayan. (vol. 1 p. 520-522). http://www.islamicweblibrary.com/wp-content/uploads/2020/04/Tafsir-Anwarul-Bayan-02.pdf