In his mercy and kindness, God revealed to Dave at a time where he was mature enough to forgive, the real reason why he was in bondage. And in that same encounter, he set him free.

But when he, the Spirit of truth, comes, he will guide you into all the truth. He will not speak on his own; he will speak only what he hears, and he will tell you what is yet to come.

John 16:13