This leads to a dilemma. If God allows some sinners to live, thus breaking the law that sin leads to death, then he would be unjust. However, for God to kill everyone because we are all sinners would be unmerciful and would not fulfil the purpose of the creation, which is to provide a place where people can freely choose to live in harmony with God.
The problem is how it could be possible to allow anyone to avoid eternal death in spite of the fact that everyone is a sinner and should hence expect to die. The solution is for someone to die on our behalf as a representative.
This was the idea of a sacrifice in the Old Testament. At a sacrifice an animal was killed with the understanding that the animal represented what should happen to the person sacrificing it and associated him with the moral principle so that he could receive forgiveness. However, an animal is an imperfect sacrifice. It cannot sin, and hence can’t properly be sinful, and it doesn’t understand what is going on and hence can’t be a willing sacrifice.
We could die ourselves - but while this is a complete vindication of the idea that sin leads to death it fails in the main purpose of the sacrifice, which is to allow us to live. We cannot represent anyone else, because we are sinful, dying creatures. When we die we will die for our own sins and not for those of others; we therefore make a poor sacrifice for anyone else.
What is needed is a sinless man who will choose, of his own free will, to die on our behalf. Jesus is exactly such a person.
When Jesus died he did not die because of his own sins. He had never broken God’s moral principle. Jesus was therefore able to die as a representative for others. The resurrection of Jesus shows that he was a sinless person; it shows the value of his death.
But in order to make Jesus our personal representative we need to take steps to associate ourselves with his sacrifice. This is the purpose of baptism.