Nathan says that David’s sin is forgiven, but he also has to tell him that the child of him and Bathsheba will die and that he will face problems with his family all of his life (see 2 Samuel 12:7–15).
You can talk about punishment in two ways. Firstly, punishment can be retribution. When you sin, you deserve death. Only faith in Jesus, who bore the penalty, gives redemption. When you believe in Jesus and him as your Saviour, God is no longer angry. Secondly, punishment can also be education. Anyone who came to Jesus became God’s child. God loves his children and disciplines them. He disciplines us so that we may share his holiness (see Hebrews 12:3–11).
1 Have mercy on me, O God, according to your steadfast love; according to your abundant mercy blot out my transgressions.