This hadeeth is one of the haadeeths that are widespread among people but are falsely attributed to the Prophet (peace and blessings of Allah be upon him).
Shaykh Hatim al-Shareef was asked about it and he said:
The hadeeth mentioned is a good example of the haadeeths which are obviously false and fabricated, and it displays poor style, weak composition and ugly meanings. Anyone who has any knowledge of the Sunnah and its splendour will have no doubt that this cannot be a saheeh hadeeth (authentic narration) that is proven to be from the Prophet (peace and blessings of Allah be upon him). I did not find it with this wording, and I wish that the questioner had told us of the source where he found this hadeeth so that we could warn the people against it.
But Abu Hamid al-Ghazaali, as was his wont (may Allah forgive him) narrated a false hadeeth in Ihya ‘Uloom al-Deen (4/130) that is similar in content to the hadeeth asked about here. In it, it says that a Bedouin said to the Messenger of Allah (peace and blessings of Allah be upon him): “O Messenger of Allah, who will be in charge of bringing the people to account on the Day of Resurrection?” The Prophet (peace and blessings of Allah be upon him) said: “Allah, may He be blessed and exalted.” He said: “He Himself?” He said: “Yes.” The Bedouin smiled and the Prophet (peace and blessings of Allah be upon him) said: “Why are you smiling, O Bedouin?” He said: “When the Most Generous is in a position to punish, He forgives, and when He brings to account, He pardons …”
Al-‘Iraqi said concerning this hadeeth: I could not find any source for it. al-Subki mentioned it among the hadeeths for which he did not find any isnad (chain of transmission). (Takhreej Ahadeeth al-Ihya, no. 3466; Tabaqat al-Shafi’iyyah al-Kubra 6/346). Nevertheless, there are many texts in the Quran and saheeh Sunnah which speak of the vastness of Allah’s mercy and the greatness of His pardon, and His acceptance of repentance and His answering prayers for forgiveness.
Allah says (interpretation of the meaning):
“And verily, I am indeed forgiving to him who repents, believes (in My Oneness, and associates none in worship with Me) and does righteous good deeds, and then remains constant in doing them (till his death).”
“And He it is Who accepts repentance from His slaves, and forgives sins, and He knows what you do.”
“… and My Mercy embraces all things. That (Mercy) I shall ordain for those who are the Muttaqoon (the pious), and give Zakah (the poor-due); and those who believe in Our ayat (proofs, evidences, verses, lessons, signs and revelations, etc.).”
In Saheeh al-Bukhari (7554) and Saheeh Muslim (2751) it is narrated from Abu Hurayrah (may Allah be pleased with him) that the Prophet (peace and blessings of Allah be upon him) said: “Allah wrote down a decree before He created the universe: ‘My mercy prevails over My wrath.’” And Allah knows best. End quote.
And Allah knows best.