There seems to be an inconsistency between the principle of no compulsion in religion and the punishment meted out to several ummahs in the past. If the former is a basic principle, why is the latter necessary?
I believe that following passage from Mr Ghamidi's research on the issue of apostasy discusses this question:
"It is an indisputable fact that it wasn't incumbent upon God to give us life as well as means of sustenance. This life and other blessings He has granted us in order to test us. The span of one's life on earth is predetermined. One remains in trial of life, and only enjoys the respite granted to him until when the Wise and all Knowing God sees fit. The Lord then sends down the angel of death who takes him back to His presence.
God determines the duration of the test for individuals as he wills. However, if a Messenger is sent among a people, and they are directly communicated the truth through the Messenger of God, they are subjected to a specific divine plan in this regard. The Holy Qur'an clearly explains the details of this divine plan. It says that these people are exposed to stark truth and that they are left with no excuse to reject it. If, however, they do persist in rejection they lose their right of life. Because the basic purpose of their life was to test them whether they obey their God, as the truth is unveiled to them in its ultimate form and they obstinately reject it, the Almighty punishes them by death. This explains the established law of the Almighty regarding the addressees of the Messengers of God."
Thus according to the view point of our school the trial of life and principle of no compulsion is a permanent one. It is only the improbability of the clarification of the religious truths in general circumstances that the Almighty does not hold us into account and does not punish anyone on whatever sin he commits. This principle was not applied in case of those to whom the Messengers of God were sent. They were exposed to the truth in ultimate form and were punished only after they rejected it after being convinced of it. When there remained no means to know who is knowingly rejecting the truth and when this truth has been unveiled to them in ultimate form there has been no such punishment.
Thus the basic criterion regarding the divine dealing with these people were not their other worldly sinful activities but their rejecting the Messengers of God knowingly. One remains in trial when the truth is not unfolded to him in this world. Until it is unveiled to him in clear form he enjoys the freedom of choice between the good and evil. But when it can be ascertained that he is not rejecting it because of some confusion or misunderstanding he can be held into account for that. This also serves as an example of the divine judgment on the Last Day and a sign of God's power to hold people into account. Thus the others are afforded with a clear sign of divine hand in the affairs of the world.
I hope this helps.