God didn’t unjustly punish Jesus instead of us, something much deeper happened. God performed the opposite transaction in Jesus that he does in us.
In him, we die to sin and are made alive, but when Jesus was made like us, he died as us. He was a man in all ways like we are, yet without sin (Hebrews 4:15), but God changed that on the cross. He made Jesus a sinner by nature. Jesus never sinned, but God made him to be sin. If he didn’t, God would be unjust in punishing our sin in Jesus.
2 Corinthians 5:21 God made Him who knew no sin to be sin on our behalf, so that in Him we might become the righteousness of God.
God didn’t symbolically place our sin on Jesus like an Old Covenant lamb. He quite literally made Jesus to BE sin to the core.