The imam made a mistake in the intention for the prayer, so he interrupted the prayer and said the opening takbir again, but the people praying behind him were not aware of that
Question

I was leading the people in praying Zuhr, but when I said the opening takbir, I intended to pray ‘Asr by mistake. After I said the opening takbir, I remembered that I was supposed to be praying Zuhr, not ‘Asr. But the people who were praying behind me had already said the opening takbir, and there were many of them. I got confused about what I should do, so I intended to myself to interrupt the prayer, then I said the opening takbir again, with the intention of praying Zuhr and leading the worshippers in prayer, and I completed the prayer with the worshippers. What is the ruling on my prayer, and what is the ruling on the prayer of those who were praying behind me? What should the imam do if something like this happens to him, because no one can avoid making mistakes sometimes.
Praise be to Allah.Your prayer is valid, as is the prayer of those who were praying behind you, because they were not aware of their imam’s situation, and they believed that his prayer was valid, as in the case of one who prayed behind an imam then they found out that he was in a state of impurity.
The fact that you interrupted your prayer then resumed leading them in prayer does not matter, because if the imam’s prayer becomes invalid, it is permissible for the members of the congregation to complete their prayer individually, or for someone to step forward and lead them in prayer.
By the same token, if the regular imam is late for the prayer and the people appoint one of their number to lead them in prayer, it is permissible for the regular imam to go forward to lead the people in prayer (when he arrives), and for the imam who had started leading them in prayer to step back and join the congregation, as the Prophet (blessings and peace of Allah be upon him) did when Abu Bakr led the people in prayer. Al-Bukhari (368) and Muslim (418) narrated that ‘A’ishah (may Allah be pleased with her) said: The Messenger of Allah (blessings and peace of Allah be upon him) instructed Abu Bakr to lead the people in prayer, when he was sick, so he used to lead them in prayer. ‘Urwah said: Then the Messenger of Allah (blessings and peace of Allah be upon him) began to feel a little better, so he came out and saw Abu Bakr leading the people in prayer. When Abu Bakr saw him, he stepped back, but he gestured to him to stay where he was. Then the Messenger of Allah (blessings and peace of Allah be upon him) sat down beside Abu Bakr, then Abu Bakr followed the prayer of the Messenger of Allah (blessings and peace of Allah be upon him) and the people followed the prayer of Abu Bakr.
If the imam realises that he did not intend to offer the obligatory prayer, then he should interrupt his prayer and inform the congregation about that, so that he and they can start the prayer all over again. He should not feel too embarrassed to do that, because forgetfulness is a human characteristic and even the best of humanity, the Prophet (blessings and peace of Allah be upon him), made mistakes in his prayer. But if he fears that it will cause confusion to the worshippers, there is nothing wrong – in that case – with him asking one of the worshippers to step forward and lead the people in completing the prayer, and he may step back and join the congregation, and start the prayer all over again behind this (new) imam.
And Allah knows best.