The Talmud Kesubos 9a says it was forced. In the case of force, the rule that the two are not allowed to subsequently marry doesn't apply.
Rav Amnon Bazek argues here that this force wasn't rape in the classic sense, but rather she had no choice about going to the king, as when the king sends guards to get you, you can't refuse. Unstated is the underlying fact that the rule is תחילתו באנוס וסופו ברצון שמי' אונס - if it starts out as forced, even if she desires it later, we say her Yeitzer Hara took hold of her, and she is blameless*. So it is still in the same category of not forbidding a subsequent marriage.
However, this is one of the questions that pushes the conclusion the other way (e.g. the Malbim uses that question to make the argument) - that Dovid, at the end of the day, didn't sin.
*This is a Machlokes there, and it is a further Machlokes Rishonim if this is a biblical issue, or strictly a question of rabbinic stringency. If it is the former, then you can't keep with the opinion that this was forced, and thus makes it permitted, you would need the other answer (that they were in fact divorced). However the Halacha is like the opinion that it is still regarded as forced.