Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:38:24

˹David˺ said, "He has certainly wronged you in demanding your ewe ˹in addition˺ to his ewes. And indeed, many associates oppress one another, except for those who believe and do righteous deeds - and few are they." And David became certain that We had tried him, and he asked forgiveness of his Lord and fell down bowing ˹in prostration˺ and turned in repentance ˹to Allah˺.  

He said, ‘He has certainly wronged you by asking for your ewe that he may add it to his sheep. And indeed many associates infringe upon ˹the rights of˺ one another, except such as believe and perform righteous deeds, but few are they!’ (mā emphasises the ‘fewness’). As the two angels were ascending to the heaven one said to the other, ‘He has certainly passed judgement on himself!’ David was thus alerted ˹to his deed˺. God, exalted be He, says: And David thought, in other words, he became certain, that We had indeed tried him, that We had caused him to fall into a trial, that is, a test, through his love for that woman. So he sought forgiveness of his Lord and fell down bowing, in other words, prostrate, and repented.
القرآن:٣٨:٢٤

قَالَ لَقَدْ ظَلَمَكَ بِسُؤَالِ نَعْجَتِكَ إِلَىٰ نِعَاجِهِ ۖ وَإِنَّ كَثِيرًا مِنَ الْخُلَطَاءِ لَيَبْغِي بَعْضُهُمْ عَلَىٰ بَعْضٍ إِلَّا الَّذِينَ آمَنُوا وَعَمِلُوا الصَّالِحَاتِ وَقَلِيلٌ مَا هُمْ ۗ وَظَنَّ دَاوُودُ أَنَّمَا فَتَنَّاهُ فَاسْتَغْفَرَ رَبَّهُ وَخَرَّ رَاكِعًا وَأَنَابَ ۩  

{قال لقد ظلمك بسؤال نعجتك} ليضمها {إلى نعاجه وإن كثيرا من الخلطاء} الشركاء {ليبغي بعضهم على بعض إلا الذين آمنوا وعملوا الصالحات وقليل ما هم} ما لتأكيد القلة فقال الملكان صاعدين في صورتيهما إلى السماء: قضى الرجل على نفسه فتنبه داود قال تعالى: {وظن} أي أيقن {داود أنما فتناه} أوقعناه في فتنة أي بلية بمحبته تلك المرأة {فاستغفر ربَّه وخرَّ راكعا} أي ساجدا {وأناب}.