All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
It is a Sunnah for whoever commits a sin and wants to repent from it to pray two Rak'ahs and ask Allah’s Forgiveness for the sin he committed. This prayer is desirable according to the view of the four Schools of jurisprudence for the Hadeeth reported by at-Tirmithi and others from Abu Bakr as-Siddeeq that he said: “I heard the Prophet the Prophet saying: ‘Any man who commits a sin then gets up, purifies himself and prays then asks Allah’s Forgiveness, Allah forgives him. Then he recited this verse (which means) {And those who, when they commit an immorality or wrong themselves [by transgression], remember Allah and seek forgiveness for their sins - and who can forgive sins except Allah? - and [who] do not persist in what they have done while they know.} [Quran 3: 135]’"
Allah knows best.