Awwam reported,

I asked Mujahid about the prostration in Surah Sad. He said, "I asked Ibn Abbas, 'On what basis did you prostrate here?'Ibn Abbas replied, 'Do you not recite "And from his descendants, Dawud and Sulayman" [Anam 6:84], "Those are the ones whom Allah has guided, so follow their guidance" [Anam 6:90]? Dawud was among those whom your Prophet was commanded to follow. Dawud عليه السلام prostrated at this verse, so the Messenger of Allah ﷺ prostrated at it as well.'"

Azami 13176

Sahih

عن العوام قال

سألت مجاهدا عن سجدة في {ص}، فقال: سألت ابن عباس: من أين سجدت؟ فقال: أو ما تقرأ {ومن ذريته داود وسليمن}[سورة الأنعام: ٨٤] {أوليك الذين هدى الله فبهداهم اقتدة} [الأنعام: ٩٠] فكان داود ممن أمر نبيكم أن يقتدي به، فسجدها داود عليه السلام، فسجدها رسول الله ﷺ.

الأعظمي 13176صحيح
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 13176 (2nd edition)
Azami 13176