The Prophet ﷺ gave a sermon and said, "When one of you arrives and the imam has already come out, let him pray two rakahs."
حدثنا محمد بن جعفر حدثنا شعبة عن عمرو بن دينار قال سمعت
أن النبي ﷺ خطب فقال إذا جاء أحدكم وقد خرج الإمام فليصل ركعتين
Its chain of transmission is sahih, previously mentioned at 14342.