And shake toward you the trunk of the palm tree; it will drop upon you ripe, fresh dates. (Surah Maryam 19:25)
Muslims believe in one God, Allah. This belief or faith (Iman) has 6 pillars, including belief in Allah, His angels, His books, His Prophets, the Day of Resurrection and Qadr (fate /decree). You can find out more from here.
Belief in Qadr has various conditions such as believing that Allah is The Creator, that everything that happens has already been written, that nothing happens except by the will of Allah and that Allah is The Creator of all actions. You can find out more from here.
One might wonder then why people are responsible for their actions and for sinning if everything has already been written from before. This requires some explanation to grasp this concept.
To take an analogy; teachers are often able to judge whether a student is dedicated or not and /or eager to learn and can often tell after some time whether the student will pass or not before completing a course. Being human however, sometimes teachers can misjudge students but as a whole they can predict whether they will pass or fail. Allah is The Creator so knows everyone better than they know themselves so can judge who will do well in this world and who will be evil or sinful but will not make a mistake with this and /or treat anyone unfairly. So what are people judged on and why do they sin?
With the case of humans, success is often based on how much materialistic benefits they gain such as having more money, having a larger house /property, having a large family and more. This is different from the Islamic point of view.
The main criteria for success are explained in the Quran: “By time, Indeed, mankind is in loss, Except for those who have believed and done righteous deeds and advised each other to truth and advised each other to patience.” (Surah Al Asr)
The Prophet PBUH (Peace Be Upon Him) said: “Actions are according to intentions, and everyone will get what was intended. Whoever migrates with an intention for Allah and His messenger, the migration will be for the sake of Allah and his Messenger. And whoever migrates for worldly gain or to marry a woman, then his migration will be for the sake of whatever he migrated for.” (Sahih Bukhari and Muslim)
Also, people are responsible for their efforts. It is mentioned in the Quran:
وَهُزِّىٓ إِلَيْكِ بِجِذْعِ ٱلنَّخْلَةِ تُسَٰقِطْ عَلَيْكِ رُطَبًا جَنِيًّا
Based on the above, people are responsible for their belief, doing good deeds and calling others towards good. They are also responsible for their intentions and effort.
Notice the example given; Maryam (Mary) PBUH was in great difficulty and pain due to labour pain and was ordered to shake the palm tree. This is something extremely difficult even for well trained athletes and yet she was commanded to do this. She did what she was told however and will be rewarded according to her efforts. Whether she was able to successfully shake the tree is another issue that she was not responsible for and the final result has been decreed. Likewise, people need to have good intentions and try their best.
An example of people being rewarded for their intentions and effort could be of someone who tries to go for the Hajj (pilgrimage) and tries to make all the necessary preparations but then their flight gets cancelled; maybe they will still get the reward as if they went for Hajj. Likewise, if someone is fasting but then forgets that they are fasting and accidentally eats something they might get the reward for fasting as they did not intend to break their fast.
Allah is aware of all things and people have been given free will to choose and do whatever they want. Everyone is also born without any sins.
In the end, people are rewarded or punished according to their intentions and effort and with the mercy of Allah, The Merciful. This includes belief. For examples: Waraqa Ibn Nawfel (cousin of Khadija, the first wife of the Prophet PBUH) who was a Christian but did not agree with many of the common beliefs of the polytheists at the time and he discussed the Prophet’s first revelation with him and recognised that the angel Jibreel (Gabriel) was the same angel who came to Maryam PBUH. However, he died shortly afterwards and was not a companion of the Prophet PBUH but there are narrations that refer to him being rewarded. Another example is Zaid Ibn Amr who did not agree with the polytheistic beliefs at the time and asked the Jews and Christians at the time about their beliefs but did not agree with many of the things that they did and remained monotheistic so again there are narrations that refer to him being rewarded.