The Prophet ﷺ said: When an imam stands up at the end of two rak'ahs , if he remembers before standing straight up, he should sit down, but if he stands straight up, he must not sit down, but perform the two prostrations of forgetfulness. Abu Dawud said: I have not narrated in this book of mine any hadith from Jabir Al-Ju'fi (one of the narrators) except this one. (Using translation from Abū Dāʾūd 1036)
قَالَ رَسُولُ اللهِ ﷺ إِذَا قَامَ الْإِمَامُ فِي الرَّكْعَتَيْنِ فَإِنْ ذَكَرَ قَبْلَ أَنْ يَسْتَتِمَّ قَائِمًا فَلْيَجْلِسْ وَإِنِ اسْتَتَمَّ قَائِمًا فَلَا يَجْلِسْ وَيَسْجُدْ سَجْدَتَيِ السَّهْوِ