He knew before the world began that we would've sinned and the salvation on the cross was already His plan before the creation but in His infinite love He wanted to let us the choice to choose beetween evil and good and so He did accepted to died for us in advance