Here's an overview of Romans 5 as I understand it.
In Romans chapter 5, Paul teaches that Adam sinned as the representative for all of his descendants. And that based on his sin, God considers all of the human race to be sinners. And Sin brings God's judgments of death in all of its forms, sickness, war, famine, poverty, etc.
Paul teaches that those (which would include infants) that never consciously sinned the way Adam did, also die as a result of Adam's sin. This would explain the Just slaughter of women and children in the conquest of Canaan. All die as a result of Adam's sin.
In Christian Theology we call it the Doctrine of Original Sin. In the Ten Commandments, God says he visits the sins of the fathers unto the children for many generations
Exodus 20:5. So not only did Adam's sin bring God's wrath on all, so do the sins of ancestors.
But Paul also teaches that just as Adam sinned as our representative causing all to suffer the penalty of his sin, God placed Jesus, the second Adam, under the trial of obedience on behalf of his children. Where Adam sinned, Jesus remained righteous. And just as God constituted all to be sinners in Adam, he constituted all of Christ's children to be perfectly righteous. Based solely on Christ's righteousness imputed to them. This is no doubt why Paul prefers Christ's imputed righteousness to his own meager righteousness. And also explains why the works of the Law cannot save.
A simple analogy would be; God took Adam, the best human and tested him for sin on behalf of all under the best conditions. Adam failed on behalf of all his children bringing sin and death on all.
God took Jesus the second Adam, and tested him under the worst conditions throughout his life and especially on the cross. Jesus passed the test not only for himself but for all of his children as well. So God imputes Jesus' righteousness to them, just as he imputed Adam's sin to his children.