EDIT: Thanks a lot to Mike Miller for pointing out in the comments significant simplifications to the proof I wrote
First suppose that $p$ does not divide $n$. Then we have
$$H^*(D_{2n};\mathbb{F}_p)=\begin{cases}\mathbb{F}_p & \textrm{ if }n=0\\ 0 &\textrm{ otherwise}\end{cases}\,.$$
Otherwise, let us suppose that $p$ divides $n$.
Let $C_n$ be the subgroup of $D_{2n}$ consisting of rotations. This is a normal cyclic subgroup of index 2. Hence, it has cohomology of the form
$$H^*(C_n;\mathbb{F}_p)=\mathbb{F}_p[a,b]/a^2$$
where $a$ is in degree 1 and $b$ is in degree 2. So now we can deploy the Lyndon-Hochschild-Serre spectral sequence
$$H^*(D_{2n}/C_n;\,H^*(C_n;\mathbb{F}_p))\Rightarrow H^*(D_{2n};\mathbb{F}_p)\,.$$
Since $D_{2n}/C_n$ has order prime to $p$, the spectral sequence degenerates and we arrive at
$$H^*(D_{2n};\mathbb{F}_p)\cong H^*(C_n;\mathbb{F}_p)^{D_{2n}/C_n}\,.$$
Note that $D_{2n}/C_n\cong \mathbb{Z}/2$ acts on $C_n$ by sending $z$ to $z^{-1}$. To conclude then it's enough to determine the action of $\mathbb{Z}/2$ on $a$ and $b$.
Let us fix a generator $x\in S$. Then a representative for $a$ is given by the cocycle $\varphi(x^k)=k$, so $\sigma\varphi=-\varphi$, and $\sigma a = -a$.
Moreover, by looking at the Serre spectral sequence for $BC_n→BS^1→BS^1$, we see that $b$ is the image of the generator of $H^2(BS^1;\mathbb{F}_p)$ under the inclusion of $C_n$ in $S^1$, and the action of $\mathbb{Z}/2$ extends to $S^1$. By the Hurewicz theorem we have an isomorphism
$$\mathrm{Hom}(\pi_2BS^1;\mathbb{F}_p)\cong H^2(BS^1;\mathbb{F}_p)\cong H^2(BC_n;\mathbb{F}_p)$$
compatible with the action of $\mathbb{Z}/2$. In particular the action is nontrivial (since the action on $\pi_2BS^1\cong \pi_1S^1\cong\mathbb{Z}$ sends $1$ to $-1$), so $\sigma b= - b$.
Finally
$$H^*(D_{2n};\mathbb{F}_p)\cong \left(\mathbb{F}_p[a,b]/a^2\right)^\sigma \cong \mathbb{F}_p[ab,b^2]/(ab)^2$$
In particular it is $\mathbb{F}_p$ in degrees congruent to $0$ and $3$ mod 4, and 0 otherwise.