(condensed from Ein Ayah, Shabbat 2:39)
Gemara: Another explanation of the pasuk "I praise the dead, who already died" (Kohelet 4:2) – it is as Rav Yehuda said in the name of Rav. That which it says, "[Hashem], do for me [David] a sign for good, and my enemies will see and be embarrassed" (Tehillim 86:17). David said before Hashem: "Master of the Universe, forgive me for that sin [Batsheva]." Hashem said: "It is forgiven." David said: "Do for me a sign [of the forgiveness] during my lifetime." Hashem said to him: "During your lifetime I will not make it known; in the lifetime of your son Shlomo, I will make it known."
Ein Ayah: Sin makes an impact upon a person that prevents him from becoming elevated to the point that he was previously capable of according to his aptitude for sanctity with good attributes and a spirit of giving. Therefore, the main part of being forgiven by Hashem is that his heart will be prepared to accept the good light of wisdom and justice the way it was prepared to before the sin.
Besides the innate level of the spirit, another matter of interest is the level of impact that a person of stature can make on the status of goodness and justice in the world. A righteous person has an impact not only through his actions, but also his grandeur makes an impression on the external world, which can give the world crucially needed merit. The greater the person’s righteousness, the greater his impact on the external world. That is why David Hamelech was not satisfied with the simple forgiveness for the sin in regard to the restoration of his inner spiritual strength, including ruach hakodesh and the light of Hashem and the joy of His salvation. Rather, David wanted a sign, or, in other words, that his positive impact on others would recover from the period during which it was flawed to its level before the sin. That way he could once again cause people to do good and fill each person who spoke of him with a spirit of sanctity.
In fact, it is impossible to return someone to the highest level during his lifetime, for it is impossible to fully appreciate someone when he still alive. Only after he has moved on is it possible to make a clear calculation of his actions in the world and his surroundings. The longings for one who is no longer among the living function to remove the disregard that entered people’s minds due to his sin, as repentance does not automatically remove the negative impression. That is because repentance can be accepted by pure intellect, but one’s feelings cannot fully appreciate its value.
The longings of the members of the righteous person’s generation after his death are an antidote for the disease that prevents the imagination from realizing the true value and strength of repentance. After the death of one who repents, full value will once again be restored in the world’s eyes. That is what the gemara hints at when saying "During your lifetime I will not make it known; in the lifetime of your son Shlomo, I will make it known."