I asked Mujahid about the prostration in Surah Sad. He said, "I asked Ibn Abbas, 'On what basis did you prostrate?'He replied, 'Do you not recite "And from his descendants, Dawud and Sulayman" [Anam 6:84], and "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, and the Messenger of Allah ﷺ performed this prostration.'"
سألت مجاهدا عن سجدة {ص} فقال: سألت ابن عباس: من أين سجدت؟ فقال: أو ما تقرأ: {ومن ذريته داوود وسليمان} {أولئك الذين هدى الله فبهداهم اقتده} فكان داود ممن أمر نبيكم أن يقتدي به، فسجدها رسول الله ﷺ.
Bukhari related it in the Tafsir (4807) from Muhammad bin Abdullah, who said, our teacher Muhammad bin Ubayd Tanafisi told us, from Awwam, and he mentioned it. He also related it (4806) through the route of Shubah, from Awwam, and in it, Ibn Abbas used to prostrate at that verse.He also related it in the chapters on the Prophets (3421) through the route of Sahl bin Yusuf, who said, I heard Awwam, and in it, your Prophet is among those commanded to follow their example.Ibn Khuzayma (551) related it, and from him Ibn Hibban (2766), through the route of Abu Khalid Ahmar, from Awwam, and in it, Dawud had prostrated at it, and so the Messenger of Allah ﷺ prostrated as well.