I think the following may give an example $X$ where the image of the map in question is not primitive.

Let $S$ be the blow-up of $\mathbb{P}^2$ in 9 points that are the intersection of two cubics (so $|{-}K_S|$ is an elliptic pencil). Let $Y \subset \mathbb{P}^1 \times S$ be a general element of $|2H -2K_S|$, for $H$ the hyperplane class of $\mathbb{P}^1$. The linear system is base-point-free, so $Y$ can be taken to be smooth. Let $X$ be the double cover of $\mathbb{P}^1 \times S$ branched over $Y$.

Then anticanonical divisors $D$ of $X$ are double covers of $S$, branched over an element of $|{-}2K_S|$, so $D$ is a K3 with non-symplectic involution whose fixed set is a disjoint union of two elliptic curves. According to Nikulin's classification, the invariant part $N \subset H^2(D)$ (which is generically equal to $\mathrm{Pic}(D)$) is a rank 10 even lattice with signature (1,9), discriminant group $N^*/N \cong (\mathbb{Z}/2)^8$ and alternating discriminant form (in the sense that $t^2 \in \mathbb{Z}$ for every $t \in N^*$). (In other words $N$ is isometric to $2E_8 \oplus U$.) The image $N'$ of the pull-back of the projection $D \to S$ is a sublattice of $N$, with $N' \cong 2H^2(S)$. So $(N')^*/N' \cong (\mathbb{Z}/2)^{10}$, and $N'$ must be an index 2 sublattice of $N$. Concretely, $-K_S$ is a primitive element of $H^2(S)$ whose image in $H^2(D)$ is even.

Meanwhile, I think that one can prove that the pull-back map $H^2(\mathbb{P}^1 \times S) \to H^2(X)$ is an isomorphism. Consider the projectivisation $Z$ of the rank 2 bundle $-K_S \oplus \underline{\mathbb{C}}^2$ over $S$ (so $\pi : Z \to S$ is a $\mathbb{P}^2$-bundle), and let $T$ be the tautological line bundle over $Z$. Then $X$ can be viewed as an element of the linear system $|{-}2T -2 \pi^*(K_S)|$, and I think one can apply a version of the Lefschetz hyperplane theorem (Goretsky-MacPherson or de Cataldo-Migliorini) to show that $H^2(Z) \to H^2(X)$ is an isomorphism.

If correct, this means that the image of $H^2(X) \to H^2(D)$ equals $N'$, so isn't primitive in $H^2(D)$.

<b>Edit</b>: Here is a rather easier example. Fix a line in $\mathbb{P}^3$, and consider a generic quartic K3 $D$ containing that line. Its Picard lattice is generated by the hyperplance class $H$ and by the Poincare dual $L$ to the line, and is isometric to
$$ \begin{pmatrix} 4 & 1 \\ 1 & -2 \end{pmatrix}  $$
Now take a class like $5H+2L$, which is ample. Thus $|5H+2L|$ contains a smooth curve $C$. Let $X$ be the blow-up of $\mathbb{P}^3$ in $C$. The proper transform of $D$ in $X$ is isomorphic to $D$, and is an anticanonical divisor of $X$. The image of $H^2(X) \to H^2(D)$ is generated by $H$ and the Poincare dual to $C$ (i.e. $5H+2L$), so is not primitive.