The purpose in Jesus coming to earth was to die for our sins, to pay the price that we deserved to pay. His death and resurrection didn't take him by surprise. As recorded in 3 of the Gospel accounts, Jesus predicted his death and resurrection.
Matthew 17:22 Now while they were staying in Galilee, Jesus said to them, “The Son of Man is about to be betrayed into the hands of men, and they will kill Him, and the third day He will be raised up.” And they were exceedingly sorrowful.