It is mustahabb for the penitent to strive hard in doing righteous deeds as well as offering this prayer, because Allaah says (interpretation of the meaning): There is no report from the Prophet (peace and blessings of Allaah be upon him) to say that it is mustahabb to recite any particular soorahs in these two rak’ahs, so the worshipper may recite whatever he wants. After that it is prescribed to ask Allaah for forgiveness, because of the hadeeth of Abu Bakr (may Allaah be pleased with him). It is prescribed for the one who is repenting to pray alone, because it is one of the naafil prayers that it is not prescribed to offer in congregation.
The prayer of repentance is two rak’ahs, as it says in the hadeeth of Abu Bakr al-Siddeeq (may Allaah be pleased with him).
End quote from Majmoo’ al-Fataawa (23/215). If a person commits a sin, then it is obligatory to repent straight away, and it is recommended for him to pray two rak’ahs, then repent, as it says in the hadeeth of Abu Bakr al-Siddeeq. The same applies to the prayer of repentance. Shaykh al-Islam Ibn Taymiyah said: Prayers which are done for a reason, such as the prostration of recitation, greeting the mosque, the eclipse prayer, prayer immediately after purifying oneself, as mentioned in the hadeeth of Bilaal, and istikhaarah prayer should not be delayed if the reason comes up at a time when prayer is disallowed, because delaying them may cause one to miss them, such as if the one who is praying istikhaarah may miss the thing concerning which he is seeking guidance if he delays the prayer. This prayer is prescribed at all times including times when prayer is disallowed (such as after ‘Asr prayer), because it is one of the prayers that are done for a reason, so it is prescribed when the reason for it is present. The Prophet (peace and blessings of Allaah be upon him) said: “Whoever repents before the sun rises from the west, Allaah will accept his repentance.” Narrated by Muslim (2703). The Messenger of Allaah (peace and blessings of Allaah be upon him) said: “Allaah will accept the repentance of His slave so long as the death rattle has not yet begun.” Classed as hasan by al-Albaani in Saheeh al-Tirmidhi (3537). (i) When the soul reaches the throat (at death). The sinner must hasten to repent but if he delays it, it will still be accepted, because repentance is accepted so long as one of the following impediments does not occur: It is mustahabb to offer this prayer when the Muslim has decided to repent from the sin that he has committed, whether this repentance comes immediately after committing the sin or later on.