Answered by Shaykh Hamza Karamali, SunniPath Academy Teacher
I was praying behind a Hanafi Imam who prostrated for forgetfulness (Hanafi style) at the end of his prayer because he omitted something that called for a forgetfulness prostration in the Hanafi school but not in the Shafii school. I wasn’t sure what to do, so I prostrated with him and repeated my prayer later on. What should I have done?

In the Name of Allah, Most Merciful and Compassionate
Shaykh al-Sharqawi (Allah have mercy on him), the Shaykh of al-Azhar during the 13th Islamic century, said in his supercommentary on Shaykh al-Islam Zakariyya al-Ansari’s priceless Tuhfat al-Tullab bi Sharh Tahrir Tanqih al-Lubab:
“If one’s Hanafi imam, for example, makes a forgetfulness prostration for something that calls for it according to him but not according to oneself, it is not permissible for one to follow him [h: in the forgetfulness prostration] because of one’s own belief [h: which holds that it is not permissible for one to prostrate]. However, one should perform a forgetfulness prostration [h: after the imam has said his salams] after this because according to one’s own belief, he has performed something that calls for the forgetfulness prostration.” (Hashiyat al-Sharqawi, 1.315)
In other words, one should remain sitting while the imam makes his forgetfulness prostration (to follow him would invalidate one’s prayer) and then, after he makes his salams, it is sunna for one to make a forgetfulness prostration to repair what the imam did. The forgetfulness prostration is sunna in the Shafii school and if one omitted it (out of fear of what others would think, for example), it would not effect the validity of one’s prayer.
And Allah knows best.
Hamza.