This is fair because the One that God punished was Himself. God punished His Son, Jesus Christ, in our place on the cross.
Jesus was sinless and lived a life of perfect righteousness and perfect obedience to God, but not for His own benefit – for ours.
Jesus died on the cross to pay the penalty of sin, but not for himself because He had no sin. Since He had no sin, His payment of death was not required for Himself.
And so, His death can pay for the sins of others, and that is what happened on the cross. Jesus has done for us what we couldn’t possibly do for ourselves.
Since He did not deserve to die, He didn’t stay dead. God’s proof that all of this is true is the resurrection of Jesus Christ from the dead.