38-Surah Sad ( The Letter Sad ) 25
So We forgave him that; and indeed, for him is nearness to Us and a good place of return.
فَغَفَرْنَا لَهُ ذَٰلِكَ ۖ وَإِنَّ لَهُ عِندَنَا لَزُلْفَىٰ وَحُسْنَ مَآبٍ
Quran's Tafhim ( explanation)
*27) This shows that the Prophet David had certainly committed an error, and it was an error which bore some resemblance with the case of the ewes. Therefore, when he gave a decision on it, he at once realized that he was being put to the test. But the nature of the error was not such as could be forgiven, or if forgiven, it would have deposed him from his high rank. AIlah Himself says: "When he fell down prostrate and repented, he was not only forgiven but his high rank in the world and the Hereafter also remained unaffected.