>>9071581God created man and gave them free will the same way God created the angels as messengers to mankind and gave them free will. You can ask why God created them if He knew exactly what their actions would be in the future but the point is to allow those beings to have the chance to experience their own decisions so that they have no excuse in the end and understand the actions that led to the consequences.
From the Qur'an:
2:30 [Prophet], when your Lord told the angels, ‘I am putting a successor on earth,’ they said, ‘How can You put someone there who will cause damage and bloodshed, when we celebrate Your praise and proclaim Your holiness?’ but He said, ‘I know things you do not.’
2:31 He taught Adam all the names [of things], then He showed them to the angels and said, ‘Tell me the names of these if you truly [think you can].’
2:32 They said, ‘May You be glorified! We have knowledge only of what You have taught us. You are the All Knowing and All Wise.’
2:33 Then He said, ‘Adam, tell them the names of these.’ When he told them their names, God said, ‘Did I not tell you that I know what is hidden in the heavens and the earth, and that I know what you reveal and what you conceal?’
2:34 When We told the angels, ‘Bow down before Adam,’ they all bowed. But not Iblis, who refused and was arrogant: he was one of the disobedient.
2:35 We said, ‘Adam, live with your wife in this garden. Both of you eat freely there as you will, but do not go near this tree, or you will both become wrongdoers.’
2:36 But Satan made them slip, and removed them from the state they were in. We said, ‘Get out, all of you! You are each other’s enemy. On earth you will have a place to stay and livelihood for a time.’
2:37 Then Adam received some words from his Lord and He accepted his repentance: He is the Ever Relenting, the Most Merciful.