Whereas the other answers assert that Christ expiated on our behalf and reiterate what he did, I interpret the OP's question as asking how it was done. I believe the impetus for the question to lie in a tacit assumption, namely that God is rational and not arbitrary, in conjunction with an apparent lack of rationale in a substitutionary atonement. In other words, it is insufficient to say that Christ's sacrifice on our behalf was one of numerous ways in which God could have demonstrated His love for us. Instead, since God is rational, there must be a reason why this way was chosen over some other way.
***Note - I only know how to satisfactorily answer this question from an LDS perspective and beg forgiveness for any consequential perceived inadequacies.
As in all things, asking the right question is as (if not more) important than getting answers, and the right questions are likely to be gleaned from context. What's more, the reasons for choosing one course of action over any other arise out of conditions and constraints which make one selection more favorable than another, or even more favorable than all other selections. So first...
The Conditions Which Necessitate Salvation
Fallen man in a fallen world - References
More specifically: sin (spiritual death, separation from God) and mortality (physical death). Rom 5:12, Rev 20:6, Alma 12:16
God's enduring love and mercy for mankind - References
This alone is sufficient only to compel Salvation, not necessarily a Savior.
The Conditions Which Necessitate a Savior
The aforementioned conditions, plus
God's justice and integrity
More specifically, that God does not lie (Heb 6:18,Enos 1:6), and that He has decreed punishment for sin. Rom 6:23.
This leads to...
in which man is fallen and helpless to save himself, and God - who loves mankind - is unable to directly intervene because to do so would undermine His impeccable integrity and godliness.
Solution 1.0 - A Third Party
Enter Deus Ex Machina, in the form of Jesus of Nazareth. A third party who will satisfy the demands of God's justice and at the same time fulfill God's (and man's) desire for mercy.** The question, of course, is how? But first, some...
**Note the analogue embodied in the Mosaic law, in which Priests were "forbidden" from touching a corpse (Num 19:11), but somebody else - say... a good samaritan? - could. Luke 10:25-37
Firstly, God could not simply delegate forgiveness of sin and expect to be exonerated of the requisite punishment due to mankind.
Secondly, if that punishment (hell) is to be heaped upon Jesus, then how is He any better off than the rest of mankind?
Thirdly, and more to the point of the OP's question, if that punishment is to be exacted upon Jesus, how is that right? Indeed, the Mosaic law seemingly rejects substitutionary justice:
"...every man shall be put to death for his own sin." - Deut 24:16
The Book of Mormon is explicit as well, indicating that
"...there is not any man that can sacrifice his own blood which will atone for the sins of another." - Alma 34:11
but, the surrounding versus add that
"11) ...it is expedient that there should be a great and last sacrifice; ...not...of man, neither of beast...but it must be an infinite and eternal sacrifice.
12) [and]...nothing...short of an infinite atonement...will suffice for the sins of the world." - Alma 34:10-12
In light of these problems and passages, it should be clear that...
- A punishment for man's sins must be dealt - somehow.
- The sacrificial Messiah must be willing to forgive and atone for man of his own accord and on his own merits, thus exonerating God of His justice, and
- must be uniquely able to circumvent the permanence of death and Hell by some means, which leads us to...
Solution 2.0 - The Dual Nature of Christ
Jesus was uniquely able to atone for mankind's sins because he was not entirely man, nor entirely God, but both - the embodiment of God in the flesh. We first will see how this allowed Him to overcome death, and second, sin.
Because Jesus was of celestial descent (God), He inherited immortality, as can be seen by John 5:26
"For as the Father hath life in himself; so hath he given to the Son to have life in himself;"
But because He was born of a woman, He inherited mortality, apparently with the ability to "...lay down [His] life...[and] take it again" (John 10:17-18). This made Him uniquely able to suffer death as punishment for mankind, and yet raise both Himself and others from the dead.
Besides a quasi-immortal body, Jesus possessed a spirit of such caliber that He lived without sin, as described in Hebrews 4:15
"...[He] was in all points tempted like as we are, yet without sin."
This made Him uniquely able to ascend back into the presence of God, after having first suffered for sin in Gethsemane, and being forsaken of God. (Matt 27:46)
And yet, we have not established how it is "just" that he should be substituted for us - which leads us finally to...
***Disclaimer - I've never heard anybody espouse the following assertion. It is my interpretation of Biblical text and mine alone.
In the same passage where Christ asserts His immortality (John 5), He also states that
"...the Father judgeth no man, but hath committed all judgment unto the Son" - John 5:22
The final piece of the puzzle is that Christ's mission is much more broad than that of the Messiah only. By Him the worlds were made. Of Him the prophets were led. He was "...foreordained before the foundation of the world..." (1 Peter 1:20), commissioned to plan, oversee, and execute the salvation of every person who has ever lived, or will live on Earth. He is the "...the author and finisher of our faith..." (Heb 12:2), charged with our salvation, and as such it is His prerogative, and His alone to voluntarily substitute Himself in place of us. This is similar to say a military leader, who may opt to take personal responsibility for the failures of his troops, even though he himself did no wrong. This is only possible because the Kingdom of God has been committed to Christ, as implied in 1 Cor 15:24.
Hope this helps - God bless.