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.'"
سألت مجاهدا عن سجدة في {ص}، فقال: سألت ابن عباس: من أين سجدت؟ فقال: أو ما تقرأ {ومن ذريته داود وسليمن}[سورة الأنعام: ٨٤] {أوليك الذين هدى الله فبهداهم اقتدة} [الأنعام: ٩٠] فكان داود ممن أمر نبيكم أن يقتدي به، فسجدها داود عليه السلام، فسجدها رسول الله ﷺ.
Bukhari related it in the Tafsir (4807) from Muhammad bin Abdullah, who said, Muhammad bin Ubayd Tanafisi narrated to us, from Awwam, who said, and then he mentioned it. He also related it (4806) via the route of Shubah, from Awwam, in a shortened form.