In these passages is the account of the prophet Nathan coming to David to tell David that David’s sin with Bathsheba greatly displeased God. Nathan said that God would severely punish David, but David would not die spiritually.
God forgave David’s sin, but David would still be punished. This tells me that God’s forgiveness does not remove punishment. God’s forgiveness for our sins enables our entry into Heaven. However, we will still be punished for our sins here on Earth.
If we were not punished for our sins, we would not be motivated to avoid sin. We would not have a healthy fear of God. Nor would we be motivated to obey God. Therefore, it is good that God punishes us for our sins. This motivates us to lead spiritually healthy lives and receive God’s blessings rather than His discipline.