Ah,this is an old, old question. If God knew a trillion trillion years ago the fate of ever human, every ant, and every neuron, then how can there be free will? More to the point, what could possibly be the point of existing and why would God ever go through the motions of creation in the first place? Big questions that can bother the mind greatly.
And they probably will forever.
How did the idea of God knowing the future and it being impossible for Him to be wrong, come about?
Because He's omniscient, He can foresee what each person will do with his free will.
Just because G-d knows (and knew and will know) the result of every human decision, does not negate the concept of free will.
Not looking for a religious debate, and this may not be the correct answer to that age old question, but.....
I’ve told my boys as they were growing up and even now when they need reminding - Even though you have free will, God has a plan for you - so you can make bad choices and end up on the hard road, or you can make good choices and end up on the easier road - but bottom line is, you will end up where He wants you to be, it’s just how you get there that’s your choice.