Divine Decree
Muslims believe that God has knowledge of all that will happen, and everything happens according to His divine plan. While God’s knowledge is absolute, humans have free will to make choices; they are accountable for their actions, which are foreknown by God but not compelled by Him. Muslims believe that all of the human being’s actions (whether they are voluntary like standing, sitting, eating, and drinking or involuntary like falling over) exist by God’s will, predetermination of them in eternity, and His knowledge of them before their time.
We know that the human being is not compelled because he has partial will that he is able to apply on the side of good and on the side of evil, and an intellect that distinguishes between the two. Therefore, if he applies his will on the side of good, the good that he willed will appear and he is rewarded for it due to it appearing because of his action and the connection of his partial will to it. If he applies it on the side of evil, that evil appears, and he is punished due to it appearing because of his action and the connection of his partial will to it. However, the good is with God’s content and the evil is not with God’s content.
To give an example, imagine that you placed an electric light switch connected to a lamp in a hidden place in your room where your young child cannot see it, then you placed her where you are able to turn the light on and off without the girl noticing. Now you want to run an experiment to test the will of the child to see if she will obey or disobey you, without doing anything that has a real physical influence on her. So you say to the child, “Do not blow on this light in case you put it out, if you obey me, I will reward you, but if you disobey me, I will punish you.” Then you begin to observe your child without her knowing that you are observing but the child chose (with her own free will) the side of disobedience over the side of obedience and goes towards the lamp and blows on it, and in that exact moment you press the switch (secretly) and the light goes out. The child feels with certainty that she was the one who put the light out by blowing, however, you know that you are the one that put it out using the real cause. As for what occurred from the child, it was only a form of highlighting her disobedience to you, and now she would deserve (in your view) to be punished for going against you within the boundaries that you set in order to test her.
This is a close example that resembles the crime of murder. The murderer only carries apparent cause in his act of killing, however, the one killed does not die except in their stipulated lifespan according to God’s divine decree and predestination and in the way that God decreed for them. The murderer, in reality, has only established evidence against himself due to what earned of sin and disobedience with his own free will that was enabled for him.
This is summed up in the verse where Allah teaches the Prophet ﷺ how to respond to those who criticised the Muslims for going out to battle at Uhud (a battle they lost and many died):
They ask, “Do we have a say in the matter?” Say, “All matters are destined by Allah.” They conceal in their hearts what they do not reveal to you. They say, “If we had any say in the matter, none of us would have come to die here.” Say, “Even if you were to remain in your homes, those among you who were destined to be killed would have met the same fate.” Through this, Allah tests what is within you and purifies what is in your hearts. And Allah knows best what is in the hearts.[1]
[1] Quran: 3:154