$$\text{Using }\cos C+\cos D=2\cos\frac{C+D}2\cos\frac{C-D}2\ \ \ \ (1)$$
$$\cos x+\cos7x=2\cos4x\cos3x\text{ and }\cos3x+\cos5x=2\cos4x\cos x$$
So, the problem reduces to $2\cos4x(\cos3x+\cos x)=0$
If $\displaystyle\cos4x=0, 4x=\frac{(2n+1)\pi}2$ where $n$ is any integer
Else $\cos3x+\cos x=0$
Again, use $(1)$
Generalization:
Using this,
Case $1:$
$$\large S=\sum_{k=0}^{n-1}\cos (a+k \cdot d) =\frac{\sin\left(n \cdot\frac d2\right)}{\sin \frac d2} \times \cos \left( \frac{ 2 a + (n-1)d}2\right)$$
if $\sin \frac d2\ne0\ \ \ \ (*)$
$\iff \frac d2\ne m\pi\iff d\ne2m\pi$ where $m$ is any integer,
If $\displaystyle S=0,$
Case $1a):\displaystyle \sin\left(n \cdot\frac d2\right)=0,\implies n \cdot\frac d2=2r\pi\iff d=\frac{4r\pi}n$ where $r$ is any integer
But $n$ must not divide $2r,$ otherwise $d$ will be multiple of $2\pi$ which is prohibited by $(*)$
Case $1b):\cos \left( \frac{ 2 a + (n-1)d}2\right)=0\implies \frac{ 2 a + (n-1)d}2=(2s+1)\frac\pi2\iff 2a+(n-1)d=(2s+1)\pi$ where $s$ is any integer
Case $\displaystyle2: \sin \frac d2=0 \iff d=2m\pi$
$\displaystyle\implies \cos(a+k\cdot d)=\cos(a+k\cdot 2m\pi)=\cos a$ for all integer $k$
$\displaystyle\implies S=\sum_{k=0}^{n-1}\cos (a+k \cdot d) =n\cos a $ which is $0$
As $n\ne0,\displaystyle\implies a=(2t+1)\frac\pi2$ where $t$ is any integer
Observe that in the current problem, $n=4,d=2a$