The Messenger of Allah ﷺ said, narrating from his Lord, "A servant of mine committed a sin and said, 'My Lord, forgive me my sin.' Allah said, 'My servant has committed a sin and has come to know that he has a Lord who forgives sins and holds accountable for them.'" This was repeated three times, then he said, "Allah says, 'Do as you wish, I have forgiven you.'"
حدثنا بهز قال حدثنا حماد قال حدثنا إسحاق بن عبد الله بن أبي طلحة عن عبد الرحمن بن أبي عمرة
قال رسول الله ﷺ يحكي عن ربه أذنب عبدي ذنبا فقال يا رب اغفر لي ذنبي فقال تبارك وتعالى أذنب عبدي ذنبا فعلم أن له ربا يغفر الذنب ويأخذ بالذنب ثلاث مرار قال فيقول اعمل ما شئت قد غفرت لك
Its isnad is sahih. Bukhari reported it, 13/464, no. 7507, Fath al-Bari, in the Book of Tawhid, chapter on the saying of Allah Almighty, "They want to change the words of Allah" [Fath 48:15], and Muslim reported it in the Book of Tawbah, chapter on the acceptance of tawbah, 4/2112, no. 2758, with similar wording.