Crucifixion had two main purposes: punishment and deterrence. In Jesus’ execution the Romans had these purposes in mind, while God has another.

Matthew 27:32-37 New Revised Standard Version (NRSV)

The Crucifixion of Jesus

32 As they went out, they came upon a man from Cyrene named Simon; they compelled this man to carry his cross. 33 And when they came to a place called Golgotha (which means Place of a Skull), 34 they offered him wine to drink, mixed with gall; but when he tasted it, he would not drink it. 35 And when they had crucified him, they divided his clothes among themselves by casting lots;[a] 36 then they sat down there and kept watch over him. 37 Over his head they put the charge against him, which read, “This is Jesus, the King of the Jews.”