Imam Hasan al-Basri (may Allah have mercy on him) states: When a man forgets in the mosque and does not perform the prostration of forgetfulness until he has left the mosque, there is nothing upon him.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 3882