Although David had gotten away with his sin in the eyes of the people around him, God knew the truth. Thankfully, David admits his sin and is forgiven. However, there are still consequences. Those consequences don’t last forever because David has a son who will be the next king of Israel.
We often think forgiveness means there are no consequences, but that’s not true. God can forgive us for the wrong things we have done, but there can still be prison terms to serve for crimes committed, health issues caused by bad habits, or broken relationships with those we have mistreated. Although forgiveness from God is always available, the best way to live is to not sin in the first place.