There are counterexamples.
Here is a simple example, adapted from Pietro Majer's comment on the MO question concerning Injective functions on a dense set. Let $X=\mathbb{R}$ and $f(x)=x^2$, and let $D$ be the positive square rationals and the negative rationals whose absolute value is not square in the rationals. Observe that $D$ is dense. Note that $f:D\to D$ is injective, since for $d\in D$, the value $f(d)=d^2$ is always a positive square rational, and distinct elements of $D$ have distinct squares. Thus, $f^{-1}(D)=D$, as requested by the OP (but note that this is not the same as saying that $f$ is bijective on $D$), and $f$ is continuous but not injective.
The previous argument seems also to extend to finite intervals, including the unit interval.
Here are some additional counterexamples, where $f\upharpoonright D:D\to D$ is a bijection.
Let $X$ be the ordinal $\omega^2+1$, which as a topological space is the same as infinitely many convergent sequences, whose limit points converge. This space is homeomorphic to a countable closed subset of the unit interval and is therefore completely metrizable. Let $D$ be the isolated points of $X$, which is exactly the set of successor ordinals below $\omega^2$. This is dense, since the closure adds the missing limit ordinals. Let $f$ be the function that interleaves two successive sequences together into one. That, we combine the successor ordinals in the interval $[\omega\cdot 2n,\omega\cdot 2(n+1))$ to those in $[\omega\cdot n,\omega\cdot(n+1))$ by an injective function that simply interleaves the two sequences into one. This is injective on $D$ and also surjective. The function $f$ extends continuously to $X$ by mapping the limit points of the successive sequences, $\omega\cdot2n$ and $\omega\cdot2(n+1)$ both to $\omega\cdot n$, and $\omega^2\mapsto \omega^2$. Note that the extension $f$ is not injective.
A simpler version of this example, without ordinals, is to take $X$ to be $k$ and also $k-\frac 1n$ for positive integers $k$ and $n$. This is infinitely many convergent sequences. Let $D$ be the isolated points $k−\frac1n$, and let $f$ be the function that interleaves successive convergent sequences into one. This is bijective on D, but not injective on X, to which it extends continuously.