No one would probably have dared to accuse him during his time, but this does not mean that people didn't know the history, to write it down later... and the story is mainly to illustrate that God knew the truth... nothing is hidden from God... and to illustrate that it is God to whom we must answer. (I have to assume that David was repentant, but I still have not looked up his story to read it.)