He traced it back to the Prophet ﷺ, who said, "When one of you is uncertain about his prayer, let him strive to determine what he believes is correct, complete the prayer accordingly, then perform two prostrations."I did not grasp some of its wording as well as I wished.
أخبرنا محمد بن رافع قال حدثنا يحيى بن آدم قال حدثنا مفضل وهو ابن مهلهل عن منصور عن إبراهيم عن علقمة
يرفعه إلى النبي ﷺ قال إذا شك أحدكم في صلاته فليتحر الذي يرى أنه الصواب فيتمه ثم يعني يسجد سجدتين ولم أفهم بعض حروفه كما أردت
[Sahih] Bukhari narrated it in the Book of Prayer, chapter on facing the qibla wherever one is, hadith no. 401, and Muslim in the Book of Mosques, chapter on forgetfulness in prayer and the sujud for it, hadith no. 572, from the hadith of Mansur through this same chain. It is also found in Sunan al-Kubra, hadith no. 1163.