“A servant [of Allah’s] committed a sin and said: ‘O Allah, forgive me my sin.’ And He (glorified and exalted be He) said: ‘My servant has committed a sin and has known that he has a Lord who forgives sins and punishes for them.’ Then he sinned again and said: ‘O Lord, forgive me my sin.’ And He (glorified and exalted be He) said: ‘My servant has committed a sin and has known that he has a Lord who forgives sins and punishes for them.’ Then he sinned again and said: ‘O Lord, forgive me my sin.’ And He (glorified and exalted be He) said: ‘My servant has committed a sin and has known that he has a Lord who forgives sins and punishes for sins. Do what you wish, for I have forgiven you.’”
It was related by Muslim (also by al-Bukhari).