Disobedience to God's Law carries two different penalties. There is the human penalty applied for crimes with physical repercussions: theft, murder, adultery, etc.; but then there is also a divine penalty applied for sins of the heart: covetousness, faithlessness, dishonesty, and others. Justice absolutely demands this duality. A government charged with enforcing the law cannot make decisions about what goes on inside a person. Human law enforcement must concern itself only with outward expressions of disobedience. So, the person who secretly worships a god other than Yahweh should feel no wrath from the magistrate, but if the same person openly offers a sacrifice to a false god, then such a person is to be put to death (Deuteronomy 17:2-5).
So, one side of this coin is that human government is to punish outward disobedience to the Law, and the sentence may only be carried out on the basis of witnesses (Numbers 35:30), further cementing the fact that heart sins may not be punished by the human magistrate, since there are no witnesses. The other side of the coin, however, is that God looks on the heart (1 Samuel 16:7). That is the purview of His justice, and we certainly ought not to think that the retribution He has in store for transgression of His Law in the inner man is inferior to that which the human magistrate can dish out.
The greatest of all commandments in the Law is actually a heart command: "You shall love the Lord your God with all your heart and with all your soul and with all your might" (Deuteronomy 6:4, cf. Matthew 22:37). A human court cannot measure this love within a person, and so has no jurisdiction, but God can and does, and He will pour out eternal punishment on those who disobey (Matthew 25:41-46).
This duality of punitive justice - civil and divine - is the reason why Jesus died on a cross and not some other way. He was guilty of neither an outward disobedience to the Law nor an inner one, yet He suffered the consequence of both. He was put to death by the magistrate - the highest form of human punishment for crime - and He was cursed by God. The truth of the latter part of that statement is made clear to us from the Law itself:
And if a man has committed a crime punishable by death and he is put to death, and you hang him on a tree, his body shall not remain all night on the tree, but you shall bury him the same day, for a hanged man is cursed by God. You shall not defile your land that the LORD your God is giving you for an inheritance. (Deuteronomy 21:22-23)
The hanged man is cursed by God! So by being crucified, Jesus bore the wrath of a criminal against man and a criminal against God when He was neither. This is the essence of penal substitutionary atonement. Christ did not suffer the wrath of both forms of justice for His own sins, because He had none, but instead He did so for those who trust in Him (Isaiah, 53:4-6, Romans 3:21-26, Galatians 3:13).
This is the great truth of the Gospel: the sacrifice of the sinless for the sinful. Accept no substitutes.