Jesus said that we should render to the state what properly belongs to the state, and though he had taxes in mind, we might reasonably infer that giving the state the job of punishing wrongdoers is one way of giving the state its due.
At the cross, God was punishing Jesus for the sins of the world. God's justice required a penalty from sinners, and in his unspeakable love, he paid the penalty himself in the person of his crucified Son.