We know $\cos^2 x = \frac 12 (1+\cos(2x))$, so your identity is related to
$$ \frac 12\left(1 + \cos\left(\frac{4\pi}{5}\right) + 1 + \cos\left(\frac{8\pi}{5}\right)\right) = \frac 34 $$ $$ \cos\left(\frac{2\pi}{5}\right)+\cos\left(\frac{4\pi}{5}\right) = -\frac 12 $$
since $\cos \left(\frac{8\pi}{5}\right) = \cos \left(\frac{2\pi}{5}\right)$.
Many trig sums of this type can be proved with the help of complex roots of unity, and a simple application of that technique does help here.
By Euler's formula, $\cos \left(\frac{2k\pi}{5}\right) = \Re (e^{2k\pi i/5})$ where $\Re$ is the real part of a complex number.
The five values $e^{2k\pi i/5}$ with $k \in \{0,1,2,3,4\}$ are the five solutions of the polynomial equation $z^5 - 1 = 0$. The sum of these five roots must be $-\frac{a_4}{a_5}=0$ where $a_4=0$ is the coefficient of $z^4$ and $a_5=1$ is the coefficient of $z^5$.
$$ 1 + e^{2\pi i/5} + e^{4\pi i/5} + e^{6\pi i/5} + e^{8\pi i/5} = 0 $$
Since these are equal as complex numbers, their real parts must also be equal, and $\Re$ is additive:
$$ 1 + \cos\left(\frac{2\pi}{5}\right) + \cos\left(\frac{4\pi}{5}\right) + \cos\left(\frac{6\pi}{5}\right) + \cos\left(\frac{8\pi}{5}\right) = 0 $$
And since $\cos\left(\frac{2\pi}{5}\right) = \cos\left(\frac{8\pi}{5}\right)$ and $\cos\left(\frac{4\pi}{5}\right) = \cos\left(\frac{6\pi}{5}\right)$, we do get
$$ \cos\left(\frac{2\pi}{5}\right) + \cos\left(\frac{4\pi}{5}\right) = -\frac 12 $$
So to generalize, let $2n+1$ take the place of $5$, with $n$ a positive integer. Take the polynomial $z^{2n+1}-1$; its roots are $e^{2k \pi i/(2n+1)}$ for $k \in \{0,1,\ldots,2n\}$. Since the polynomial's coefficient of $z^{2n}$ is zero, the sum of these roots is zero.
$$ \sum_{k=0}^{2n} e^{2k \pi i/(2n+1)} = 0 $$
The term for $k=0$ is $1$.
$$ \sum_{k=1}^{2n} e^{2k \pi i/(2n+1)} = -1 $$
The real part of this equation is
$$ \sum_{k=1}^{2n} \cos\left(\frac{2k \pi}{2n+1}\right) = -1 $$
Split the sum into the terms where $k=2n+1-2j$ is odd and the terms where $k=2j$ is even:
$$ \left(\sum_{j=1}^n \cos\left(\frac{2(2n+1-2j) \pi}{2n+1}\right)\right) + \left(\sum_{j=1}^n \cos\left(\frac{4j \pi}{2n+1}\right)\right) = -1 $$
But $\cos\left(\frac{2(2n+1-2j) \pi}{2n+1}\right) = \cos\left(\frac{4j \pi}{2n+1}\right)$, so the two sums are equal, and
$$ \sum_{k=1}^n \cos\left(\frac{4k \pi}{2n+1}\right) = -\frac 12 $$
Apply the identity $\cos(2x) = 2\cos^2 x-1$ to get
$$ 2 \left(\sum_{k=1}^n \cos^2\left(\frac{2k \pi}{2n+1}\right)\right) -n = -\frac 12 $$
and finally,
$$ \sum_{k=1}^n \cos^2\left(\frac{2k \pi}{2n+1}\right) = \frac{2n-1}{4} $$
which matches your identity when $n=2$.