This is how I understand.
Although teacher knows who is going to pass or who is going to fail but it is teachers wish that everybody should pass and work hard to pass that is why teacher reminds everybody to try their best and change their destiny , she/he provides them equal chance and equal guidance to help them pass . Some of the students who are supposed to fail but they strive and work hard and in the end they pass.
Same applies here.
Those who believe in Allah also believe in , Mashiat a Ilahi or divine wish. Although Allah knows who is going to go into Jannat and who is going to go into hell , but Alllah’s wish is to give everybody a fair chance to change their destiny . so Allah sent everybody in this world with free will to try to change their destiny. Also That is why Allah provided guidance and equal chance to everybody Allah knows but we do not know so it is our duty to try our best to get to Jannat . You would see many who are buried deep down into sin, one day get out of that trance and become good and start doing good and change their destiny ( Inshallah).