Abdullah bin Abbas reported,

The Prophet ﷺ prostrated during Surah Sad and said, "Dawud عليه السلام performed this prostration as an act of repentance, and we perform it as an act of gratitude."

Azami 13177

Sahih

عن ابن عباس

أن النبي ﷺ سجد في {ص}، وقال: سجدها داود عليه السلام توبة، ونسجدها شكرا.

الأعظمي 13177صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Tafsir of the great Quran
Chapter
Tafsir of Surah Sad
Section
His saying, "He said, 'You have certainly been wronged by his request to add your ewe to his ewes. And indeed, many partners oppress one another, except those who believe and do righteous deeds, and few are they.' And Dawud became certain that We had tested him, so he asked forgiveness of his Lord and fell down bowing and turned in repentance. So We forgave him that, and indeed for him is nearness to Us and a good place of return." His saying "Indeed, we are" in the context of the trial of Dawud عليه السلام, there are many stories mentioned in books of tafsir transmitted from the Old and New Testaments that impugn the infallibility of the prophets, and none of them meet the standard of Jami al-Kamil, so I have disregarded them. And His saying "and fell down bowing and turned in repentance" means he prostrated to Allah and turned to Him in repentance
Numbering
Jami al-Kamil 13177 (2nd edition)
Azami 13177