The Rules of Forgetfulness (Sahw) in Prayer
Man Lā Yaḥḍuruh al-Faqīh|Volume 1|Book 1|Chapter 50
وَ سَأَلَ عَبْدُ اَللَّهِ بْنُ أَبِي يَعْفُورٍ أَبَا عَبْدِ اَللَّهِ عَلَيْهِ اَلسَّلاَمُ: عَنِ اَلرَّجُلِ يُصَلِّي رَكْعَتَيْنِ مِنَ اَلْمَكْتُوبَةِ فَلاَ يَجْلِسُ فِيهِمَا فَقَالَ «إِنْ ذَكَرَ وَ هُوَ قَائِمٌ فِي اَلثَّالِثَةِ فَلْيَجْلِسْ وَ إِنْ لَمْ يَذْكُرْ حَتَّى رَكَعَ فَلْيُتِمَّ صَلاَتَهُ ثُمَّ يَسْجُدُ سَجْدَتَيْنِ وَ هُوَ جَالِسٌ قَبْلَ أَنْ يَتَكَلَّمَ.
Abdullah ibn Abi Ya'fur asked Imam Jafar ibn Muhammad Al-Sadiq عليه السلام about a man who prays two rak'ahs of the obligatory prayer but does not sit in them. Imam عليه السلام said: "If he remembers while standing in the third rak'ah, he should sit. If he does not remember until he has already bowed, he should complete his prayer, then prostrate two prostrations while sitting before speaking."
- Ṣaḥīḥ al-Faqīh, p. 47