In order to understand why Jesus did what He did, you would need to understand Torah, which is God's eternal law as delivered to us through the mediator Moses, the friend of God. Torah is God's eternal law, which Jesus explains would remain unaltered even if heaven and earth passed from existence, ( Luke 16:7), and He says the same about His own words which are elucidations and fulfillments of that same Torah, (Mark 13:31). The overriding theme of Torah is 'love of others,' without which we have nothing and are nothing.
Those who live in obedience to Torah are part of what the Bible calls the 'Elohim Adonai,' which is a vast complex of perfectly orchestrated and coordinated beings operating as One and existing outside of the cage of time. Human beings were created in God's image in that we too were made up of vast arrays of living beings reflecting that same perfect orchestration and coordination and were invited to join the Elohim Adonai. Before this could happen however, we had to make a decision. Like all created beings, were were given choice, since liberty is foundational to the nature of God. The New Testament explains that liberty is the state where the Holy Spirit dwells. (2 Corinthians 3:17). Our choice was to either explore the mysteries of evil and gather evidence to make a decision, or accept the word of God that He alone knows what is best for each of His creations. We chose to use the method of 'evidence gathering,' which continues to this day, driving men to explore dark mysteries that presume to offer something which faith in God's nature alone cannot.
In this fallen state, there was no hope of joining the Elohim Adonai and human beings became trapped within an inescapable perception meant only to be experienced by the fallen. The Bible uses the allegory of a 'great chain' used to bind those awaiting Judgment. The inescapable perception is what we call 'time' and scientists also believe that it is essentially inescapable, representing a chasm across which anything other than infinitesimally small objects cannot travel except in fiction.
Jesus came to us to deliver us from this fallen state. However, what stood in His way was the power of His own divine law, (Torah), demanding justice for our crimes in blaspheming God by calling Him a liar as we seek evidence to support or deny His assertions and commands, rather than innocently trusting in His nature and in the example of the vast array of other beings who did make the choice to simply trust in that same Word. Why should they be subjected to the errors of the disobedient? We have what we deserve. While this is quite true, God is also unimaginably merciful and righteous as well as patient. He offers us a very clever way of escape from our circumstances, without violating His eternal Torah. However, it likewise involves choice.
God ingeniously revealed that any term within His Torah is 'negotiable.' It cannot be broken, but its interpretation can be expanded or 'elucidated' based on the foundation which is 'love of others.' This is permitted based on the merciful and patient aspects of God's nature, even though this is not required upon enforcement. Our lawyers would call this 'discretion within the law.' The New Testament Bible calls this 'grace.' We even use it regarding our silly credit cards, calling the period when we don't have to pay immediately a 'grace period.' Jesus revealed this while He walked among us, tempted by opportunities to sin in each case yet fulfilling the 618 requirements of Torah perfectly. He thus earned Himself the honor of emitting anything new which God wished to convey through the holy tradition delivered by the first mediator Moses, who confirmed Moshiach ('Messiah' or 'Christ') the new and sole mediator between God and men by means of a vision confirmed in the presence of three living human witnesses, also as prescribed by Torah (Mark 9:2-7). God revealed this idea of 'grace' in a new section of Torah called the 'law (torah) of liberty.' (James 1:25, 2:12) or the 'gospel,' meaning 'good news.' This newly emitted section explaining the commands regarding 'liberty' created a New Covenant between God and obedient humans.
According to the New Covenant, Messiah would be employing the discretion of the Torah to create a 'double definition' for a vital term within the divine law. That term is the term 'sin.' Until this elucidation, 'sin' only meant the 'state of fallenness' arising from any violation of the 618 requirements. This violation could either carry with it a sentence of death, for which there was no repentance, or a prescription of repentance to be carried out with the assistance of the Levite priesthood. Messiah declared quite ingeniously that He Himself would become 'sin,' (2 Corinthians 5:21), thus creating two distinct definitions for the term. Humans could now choose which term they wished God to use while applying the justice of His Torah to them. However, doing such a remarkable and paradoxical thing required a remarkable and paradoxical sacrifice. This required a perfectly obedient man to surrender His own 'grace' and connection with the Elohim Adonai and then allow the Elohim to respond out of their own sense of righteous justice. Their response was to martial the powers of microbiology and all required life to restore the dead body of the Messiah, since He remained innocent and His punishment was unlawful and had to be reversed. However, His choice to lay His own life down out of 'love of others' was the very heart of Torah and His embodiment of 'sin' itself was honored as a new state and legal co-definition.
We may now choose through 'love of others' to demonstrate our acceptance of this profound and mind-boggling gift, which includes a double definition for every term related to 'sin' within Torah. This means that God now always asks 'why?' King David ate the holy showbread and fed it to his friends, which was unlawful to be eaten except by the Levite priesthood. This action carried with it serious penalties. Yet David and his companions were held blameless because he was motivated by love of others. Jesus used this as an example of God anticipating the New Covenant. Any violation of Torah may now be first delayed, then forgiven, if we can answer for it out of a clear conscience because of love of others. Jesus even provided His Holy Spirit to aid us in these new interpretations. However, it is a false gospel to believe that we can do whatever we wish in Christ's name, even without love of others while still standing in legal blamelessness before God. This is called 'the way of Balaam,' (2 Peter 2:10-22, Jude 1:10-16), and is the most widespread form of 'Christianity,' offering nothing but insults to Messiah as they pursue greed and self-serving fame.