On the morning of Eid al-Fitr, when we reached the prayer place we found that the imam had prayed and was finishing his sermon, so we prayed the two rak’ahs of Eid whilst the imam was delivering the khutbah. Was our prayer valid or not?.
Eid prayer is fard kifaayah (a communal obligation); if enough people undertake it, the rest are absolved of sin. In the scenario mentioned in the question, the obligatory duty had been discharged by those who prayed first – those to whom the imam was delivering the khutbah. For those who missed it and want to make it up, it is mustahabb for them to do so, so they should pray it without a khutbah afterwards. This was the view of Imam Maalik, al-Shaafa’i, Ahmad, al-Nakha’i and other scholars.
The basic principle concerning that is the words of the Prophet (peace and blessings of Allaah be upon him): “When you come to the prayer, walk in a tranquil and dignified manner, and whatever you catch up with, pray, and whatever you miss, make it up.”
It was narrated from Anas that if he missed the Eid prayer with the imam, he would gather his family and freed slaves, then his freed slave ‘Abd-Allaah ibn Abi ‘Utbah would stand up and lead them in praying two rak’ahs in which he would say the takbeers.
The one who reaches the Eid prayers whilst the imam is delivering the khutbah should listen to the khutbah, then he should make up the prayer after that, so that he may achieve two good things.
And Allaah is the Source of strength.