Allah states that even if the people were commanded to commit what they were prohibited from doing, most of them would not submit to this command, for their wicked nature is such that they dispute orders. Allah has complete knowledge of what has not occured, and how it would be if and when it did occur. This is why Allah said,
(And if We had ordered them (saying), "Kill yourselves (i.e. the innnocent ones kill the guilty ones)) until the end of the Ayah. This is why Allah said,
وَلَوْ أَنَّهُمْ فَعَلُواْ مَا يُوعَظُونَ بِهِ
(but if they had done what they were told,) meaning, if they do what they were commanded and refrain from what they were prohibited,
The present verses and those appearing immediately earlier were revealed in the background of an incident relating to Bishr, the hypocrite. As we already know, he had first proposed Ka'b Ibn Ashraf, the Jew as the adjudicator of his dispute, but, later on, mutual discussions forced him to go to the Holy Prophet ﷺ for this purpose.
Since the judgment of the Holy Prophet ﷺ was against him, he did not accept it and went to Sayyidna ` Umar ؓ for a totally fresh decision.
When the news of this incident got around in the city of Madinah, the Jews chided Muslims by saying: 'What sort of people you really are? Here you are believing in a Messenger of Allah and claiming to follow him, yet you do not accept his decisions! Look, in -order that their repentance be accepted, the Jews were commanded to kill each other. This was a severe command, but we obeyed it, so much so that seventy thousand of our people were killed. If you were given a command like that, what would you have done?' Thereupon, the verse وَلَوْ أَنَّا كَتَبْنَا عَلَيْهِمْ (And if We had prescribed for them ...) was revealed. It means: If these hypocrites, or all common people, disbelievers or believers, were charged with some severe command, such as that of self-killing or migration like the Bani' Isra` il were ordered to do, very few of them would have, being what they are, obeyed this command.
A prophet is not sent to the world to raise a group of followers who will wax eloquent in his praise and cover him in glory. A prophet comes so that people should learn the code of conduct for their lives and adopt it in practice. One should be so thoroughly committed to doing so, that even in controversial situations, when conflicting interests have caused strained relations, one will not fail to obey the Prophet’s teachings. The true believer will simply suppress his ego and conscientiously follow the guidance of the Prophet. He will willingly accept his ways, even if they are detrimental to his interests and run counter to his way of thinking. He will remain mentally alert to any inadvertent mistake on his part, soon realizing that he had strayed from the Prophet’s path to the path of Satan. He will immediately repent, mend his ways and seek forgiveness. On the contrary, one who is not able to adhere to the straight path of the faith, when the dictates of faith clash with his feelings and desires, cannot be expected to remain steadfast in times of harder trial. At such trying times one has to give proof of one’s faith by making sacrifices for it.
Uthmani text of the Madinah mushaf (King Fahd Complex). Translation: Saheeh International. Tafsir via Quran.com.