To err is to be human. Even the most devout Muslim is bound to commit an error or a sin now and then. No human is free from sin except the prophets. Sinning is the transgression against the commands of Allah (سُبْحَانَهُ وَتَعَالَى), and it is best avoided. However, Allah (سُبْحَانَهُ وَتَعَالَى) is Oft-forgiving, and when a believer makes a dua upon committing a sin, He truly listens and forgives.
In the Quran, Allah (سُبْحَانَهُ وَتَعَالَى) addresses the Prophet Muhammad (ﷺ) and the people that "O My servants who have exceeded the limits against their souls! Do not lose hope in Allah's mercy, for Allah (سُبْحَانَهُ وَتَعَالَى) certainly forgives all sins. He is indeed the All-Forgiving, Most Merciful." (Quran 39:53)
Repentance is not only about seeking forgiveness, but it demands one to sincerely open their heart and turn towards Allah (سُبْحَانَهُ وَتَعَالَى) rather than becoming hopeless that they will not be forgiven by Allah for their misdeed and continuing to fall further in sin. Dua, upon committing a sin, is rewarded and beloved by Allah Azzawajal, given that it's made with pure intentions. In the dua below, it is stated that whenever a Muslim person commits a sin, they should make wudu and offer two rak'ah salah to seek Allah's forgiveness.
There is no specific time to make dua upon committing a sin. It is with much sincerity that we seek repentance matters. Whenever one has sinned, one should perform ablution and stand to pray two rak'ah of prayer (salah), and this is how the Prophet Muhammad(ﷺ) taught us as his sunnah [Hisn al-Muslim 140]. When making dua upon committing a sin, make sure you find a quiet place that allows you to reflect and you are truly able to humble yourself with remorse. Make dua with a firm resolution that you will not commit the same mistake again, and be mindful of your actions.
Praising Allah Duas
There is not any slave of Allah who commits a sin, then he perfects his ablution and stands to pray two rak'ah of prayer, then seeks Allah's forgiveness, except that Allah will forgive him.
When one makes dua upon committing a sin, it is an acknowledgment that one has transgressed, and one takes responsibility for one's action. This allows people not only insight into their actions but also opens up a new door in the direction of spiritual growth. Dua is the most significant and vital means of seeking forgiveness, and when a person makes dua after committing a sin, it allows one to find a way back to their Creator. This builds a stronger connection and strengthens the faith one has in Allah.