1) Punishment from Allah (swt) is a result of man willingly disregarding divine guidance and not listening to the call of the ''outer'' and "inner" messengers.
2) The knowledge of Allah (swt) regarding the way His creatures will act in different situations, in no way results in them being forced to take that method of action, and in other words, Allah's knowledge reveals His creatures’ course of action, nothing else.
3) Shaytan and other evil beings and people need to be created so that others have the chance of reaching spiritual perfection.
4) Although the creation of Shaytan and other evil people and things is a must, yet who plays this role is up to the individuals themselves.
The question of why Allah (swt) has created and punishes bad people, is one that goes back to the subject of man and free will. The question there is: ''No single person comes to this world by choice; all who come are forced to. On one hand, Allah (swt) knows the fate of each and every person, and on the other hand they have to act according to Allah’s (swt) knowledge or else that will necessitate the deficiency of Allah’s (swt) knowledge, which is impossible, therefore those who are bad, have no choice other than to be bad, so that His knowledge remains perfect; so how is this fact not in contradiction with free will?”
Here, we will discuss man and free will in order to reach a conclusion on the question:
1) Allah’s (swt) knowledge regarding the acts and behavior of His different creations doesn’t result in them being forced to do as He knows. For example, if you were to stand at a high point and watch someone drive their car, and could tell that if he/she were to continue driving at the same pace, it would surely end up in the car falling from a cliff, and after a few moments that actually happened, you wouldn’t be the one responsible just because you knew that it was going to happen. No one would say that your knowledge was the one that caused the accident. Knowing one’s fate because of his/her mistakes has nothing to do with you.
Allah (swt) isn't the one who determines the bad or good destiny of others, and never assigns a bad destiny to anyone. This hadith by the great prophet of Islam (pbuh) has been narrated by many Islamic scholars: “The prophet (pbuh) said: The Qadariyyah have been cursed by seventy thousand prophets (throughout history). It was asked: Who are the Qadariyyah? The prophet (pbuh) answered: Those who believe that they are forced to sin (because of the bad destiny that Allah (swt) has imposed on them) and that they will be punished because of these sins (that they have no control over and nothing to with and no choice about).”[1]
2) It is more appropriate to say that Allah (swt) knows who will make good use of divine guidance when it comes and who will turn away from it, and that punishment in the hereafter (or even in this world) is a result of making the wrong choice regarding that guidance. Just like the experienced teacher who lists the elements of success for his students on the first day of class, but knows who will heed his advice and take it seriously and who won't. Clearly, good grades and prizes will go to those who deserve them, and bad grades and all of the hardships that those grades entail, all will be for those who have asked for it with their actions. So all the knowledge of the teacher does in such a situation, is show him who will succeed and who won't, and has nothing to do with forcing them to be lazy or strive for success.
This is why theologians say: “Allah (swt) has knowledge regarding the obedience and disobedience of His servants, and this knowledge reveals and is determined by[2] the acts of His servants.[3]
3) If Allah (swt) was to not send any means of guidance to the people, and yet expected them to believe in and obey Him, one could object, but considering that He has sent both inner messengers (the sound intellect) and outer ones (the prophets, imams, books and scriptures and even scholars), who is the one to be truly blamed; the one who possesses many “lanterns” in the dark and still goes the wrong way, or the one who punishes him for breaking those precious and needed “lanterns”?
4) Life in this world is all about making the right choices, thus one can say that our fates are in our own hands and that it all depends on how much we strive and ask Allah (swt) for help and guidance.
5) Allah (swt) created man in order for him to reach perfection and salvation. Not only doesn’t the creation of Shaytan, who is always trying to misguide man, contradict this goal, but it is necessary, because development and perfection is always a result of struggle, clashes and conflict.[4]
6) Although the role jinni and human shaytans play is an important one in achieving the abovementioned goal, yet no one is forced to play this role, and whoever does so, does it willingly and in reality chooses to so.
Even Shaytan (Iblis) himself wasn’t created as Shaytan, because he had lived with the angels for six thousand years[5] and was a great worshipper of Allah (swt), but despite this fact, he chose to go the wrong way as a result of his self pride, distancing from Allah’s (swt) grace and mercy. The same goes with Yazid; he chose to go the wrong way, therefore he can no longer object to his creation and ask Allah (swt) why he was created, because the answer is that the role you were to play was a necessary one, but not one imposed on you, on the contrary, you are the one who chose to play it (so the role is a necessary one, but only those who choose to, play it).
In other words, there must be bad people in this world so that others can reach perfection through the encounters they have with them. Take Imam Husein (as) for instance; there must be a Yazid in order for Imam Husein (as) and what he did to find true meaning; the situation he put Imam Husein (as) in was the one that allowed the imam to reach the high level of martyrdom. Yet, Allah (swt) has forced no one to be Yazid; it is Yazid himself who chooses to be the Yazid who committed one of the greatest atrocities of all time, therefore he can't question Allah (swt) for who he is, because he himself is the one to blame.
7) The creation of man is a favor by Allah (swt) because of His never-ending grace. It is like for someone to arrange a great feast and invite others to take part in it without asking them for anything else. Now if there are people who willingly decide not to attend and make use of the food there, resulting in their hunger, the one hosting the feast isn't the one to be blamed and scolded just because he knew they wouldn’t come, because not inviting them at all is worst and in that case they would probably claim that they would have come.
[1] انه (ص) قال: لعنت القدریه علی لسان سبعین نبیاً. قیل: و من القدریة یا رسول الله؟ فقال: قوم یزعمون ان الله قدر علیهم المعاصی و عذبهم علیها. Biharul-Anwar, vol.5, pg.47.
[2] Determination here means that “the known” thing determines the knowledge itself: قال: و هو تابع بمعنى أصالة موازیه فی التطابق.
أقول: اعلم أن التابع یطلق على ما یکون متأخرا عن المتبوع و على ما یکون مستفادا منه و هما غیر مرادین فی قولنا العلم تابع للمعلوم فإن العلم قد یتقدم المعلوم زمانا و قد یفید وجوده کالعلم الفعلی و إنما المراد هنا کون العلم و المعلوم متطابقین بحیث إذا تصورهما العقل حکم بأصالة المعلوم فی هیئة التطابق و أن العلم تابع له و حکایة عنه و أن ما علیه العلم فرع على ما علیه المعلوم و على هذا التقدیر یجوز تأخر المعلوم الذی هو الأصل عن تابعه فإن العقل یجوز تقدم الحکایة على المحکی Kashful-Morad, pg.231.
[3] Khajeh Nasiruddin Tusi, Kashful-Morad, pg.230.
[4] Muhammad Bistooni, Shaytan Shenasi az Didgahe Qurane Karim, pg.17.
[5] Nahjul-Balaghah, the sermon of Qase’ah, 234.