Linking Bnai Yisrael in the Midbar; David and Batsheva; and Tefilat Shlomo:
The David and Batsheva story shows us (among other things) a basic idea in Judaism about how repentance works. Hashem may forgive the sin, but the sinner must still live with the consequences of his actions. We see this in the Midbar with Bnai Israel as a whole, and we see it with David.
This is also the famous D'var Torah in the beginning of Parshat Re'eh in D'varim: the idea that the blessing is listening to G-d and doing Mitzvot, but the curse is NOT just doing aveirot, but rather the curse is "straying from the path" and following other gods. In other words, turning completely away from G-d.
After the sin of the Meraglim, G-d says to Moshe: "14:20 And the LORD said: 'I have pardoned according to thy word. 21 But in very deed, as I live--and all the earth shall be filled with the glory of the LORD--" (Trans. JPS 1917, mechon-mamre.org). We see the same paradigm with Natan's visit to David. (Although in reverse order. Natan gives the punishment first, then says at the end that he is forgiven and won't die.)
This is is also the underlying theme in Shlomo's Tefillah in Melachim Aleph. Throughout the entire tefilah he stresses the fact that though we may sin, the main goal is to always strive to get closer to G-d, to be on the right path, to never turn completely away from G-d because we are not perfect.