The scholars differed as to whether it is permissible for the imam to pray sitting, if he is sick or unable to stand, when behind him there are people who are healthy.
The correct view regarding that is that it is permissible for him to lead the prayer and it is valid to pray behind him.
For more information, please see the answer to question no. 11465.
This is indicated by the hadith of Abu Hurayrah (may Allah be pleased with him) from the Prophet (blessings and peace of Allah be upon him), according to which he said:
“The imam is appointed to be followed, so do not differ from him. So when he bows, then bow; when he says Sami`a Allahu liman hamidah, then say Rabbana laka’l-hamd; when he prostrates, then prostrate. And if he prays sitting, then you should all pray sitting”
Narrated by al-Bukhari (722) and Muslim (417).
It should be noted that the issue that you asked about is not the issue that is mentioned in the hadith quoted above, because that imam who led you in prayer was able to stand, and he prayed standing, but he was unable to bow and prostrate, and that is a different issue.
The scholars differed regarding the ruling on praying behind one who is unable to bow and prostrate.
Shaykh Ibn `Uthaymin (may Allah have mercy on him) said in Ash-Sharh al-Mumti`:
Question: if someone is unable to bow, prostrate and sit (between the two prostrations and when reciting the tashahhud), is it valid to pray behind him?
We have noted above that the view of the madhhab is that it is not valid to pray behind him, except for one who is like him.
However the correct view is that praying behind him is valid, based on the principle that if a person’s prayer is valid, it is valid for him to lead others in prayer, unless there is evidence to the contrary. That is because this principle is indicated by the general texts, except in the case of a woman; it is not valid for her to lead men in prayer, because she is of a different gender.
Moreover, by analogy with the one who is unable to stand, the prayer of one who is able to stand behind an imam who is not able to stand is valid according to the religious texts, and the same applies in the case of an imam who is unable to bow and prostrate.
If someone were to say: the Prophet (blessings and peace of Allah be upon him) said: “If he prays standing, then pray standing, and if he prays sitting, then pray sitting, all of you,” and he did not say: if he bows then bow, and if he tilts his head (to indicate bowing), then tilt your heads.
We say in response to that: the hadith only speaks about standing, because it was spoken in the context of being unable to stand. So the Messenger (blessings and peace of Allah be upon him) addressrd them when he led them in prayer sitting; they stood, then he gestured to them to sit down, so they sat down. Hence the Prophet (blessings and peace of Allah be upon him) mentioned standing as an example, because that is what happened.
Based on that, we say that the correct view is that praying behind one who is unable to bow is valid; even if our imam cannot bow because of pain in his back, we may pray behind him.
But if he bows by tilting his head, should we also tilt our heads to indicate bowing, or should we bow properly?
What appears to be the case is that we should bow properly, because when one who is unable to bow tilts his head, that does not change the posture of standing except by tilting the head, unlike standing when the imam is sitting.
Moreover, the Prophet (blessings and peace of Allah be upon him) explained the reason why we should not stand when the imam is sitting, by noting that if we stand when our imam is sitting, we will be imitating the non-Arabs who stood whilst their kings sat. Hence in some versions of the hadith it says: “Just now you almost did what the Persians and Byzantines do; they stand when their kings are sitting. Do not do that. Rather you should follow your imam; if he prays standing then pray standing, and if he prays sitting, then pray sitting.”
So if our imam is sitting, and we are standing, we will be standing when he is sitting [which the Prophet (blessings and peace of Allah be upon him) told us not to do]. As for bowing, if he is unable to bow and he tilts his head whilst we bow properly, we will not be imitating the non-Arabs by doing that.
Similarly, if he is not able to prostrate, the correct view is that it is valid for one who is unable to prostrate to lead in prayer those who are able to prostrate, but in this case should the one who is following the imam tilt his head to indicate prostration?
The answer is no; rather he should prostrate properly.
Similarly, if he is unable to sit, we may pray behind him even though we are able to sit, such as if he is sick and cannot sit, and he prays lying on his side.
But should we pray lying on our sides?
The answer is no, because the command to do the same as our imam only applies to sitting and standing. Based on that, we should pray sitting when he is lying on his side. Similarly, if he is unable to sit between the two prostrations for example, or to sit when reciting the tashahhud, we may still pray behind him.
So the correct view is that we may pray behind one who is unable to stand, bow, prostrate and sit. This view is the one that was favoured by Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him), and it is the correct view, based on the general meaning of the evidence, such as the words of the Prophet (blessings and peace of Allah be upon him): “The people should be led in prayer by the one who has the most knowledge of the Book of Allah”; and also based on the principle that we have mentioned above, which is that if a person’s prayer is valid, it is valid for him to lead others in prayer.
End quote from Ash-Sharh al-Mumti`, 4/236-238.
The shaykh was also asked:
I entered the mosque at the time of Maghrib prayer, and a man went forward to lead the congregation in prayer. When he prostrated, he stretched out his leg and did not prostrate on the seven parts of the body; please note that his knee and foot did not rest on the ground. What is the ruling on those who prayed behind this man?
He replied:
This imam was unable to prostrate in the required manner…
The scholars differed regarding the scenario in which the imam is unable to do one of the essential parts of the prayer: is it permissible for him to lead in prayer those who are able to do that?
The correct view is that it is permissible for him to lead in prayer those who are able to do that, because what he is unable to do is waived in the case of this imam, and it is as if he did that…
But they should seek another imam who is able to do the essential parts and fulfil the conditions of prayer, because that is more prudent and on the safe side.
End quote from Fatawa Nur `ala ad-Darb (182/21).
Based on that, what you did by not praying behind this imam who was unable to bow, prostrate and sit is in accordance with the view of some of the scholars. However the more correct thing to do would have been to pray behind him, but your prayer is still valid, in sha Allah.
And Allah knows best.