For which $n$ is $ \int \limits_0^{2\pi} \prod \limits_{k=1}^n \cos(k x)\,dx $ non-zero? I can verify easily that for $n=1$ and $2$ it's $0$, $3$ and $4$ nonzero, $4$ and $5$ $0$, etc. but it seems like there must be something deeper here (or at least a trick).

Hint: Start as anon did with
$$
\int_0^{2\pi}\prod_{k=1}^n\cos(kx)\,\mathrm{d}x
=\int_0^{2\pi}e^{-i\frac{n(n+1)}{2}x}\prod_{k=1}^n(1+e^{i2kx})\,\mathrm{d}x\tag{1}
$$
which would be $2\pi$ times the coefficient of $x^{n(n+1)/2}$ in
$$
\prod_{k=1}^n(1+x^{2k})\tag{2}
$$
$(2)$ is the number of ways to write $n(n+1)/2$ as the sum of distinct even integers $\le2n$.
So $(1)$ is non-zero precisely when you can write $n(n+1)/2$ as the sum of distinct even integers $\le2n$ (a much simpler problem).

Claim: $\dfrac{n(n+1)}{2}$ can be written as the sum of distinct even integers no greater than $2n$ in at least one way precisely when $n\in\{0,3\}\pmod{4}$.
Proof: By induction.
If $n\in\{1,2\}\pmod{4}$, then $\dfrac{n(n+1)}{2}$ is odd, and so cannot be written as the sum of even integers.
Suppose that $n\in\{0,3\}\pmod{4}$ and $\dfrac{n(n+1)}{2}$ can be written as the sum of distinct even integers no greater than $2n$. Then
$$
\frac{(n+4)(n+5)}{2}=\frac{n(n+1)}{2}+(2n+4)+(2n+6)
$$
Thus, if the statement is true for $n$, it is true for $n+4$.
Once we note that $\dfrac{3(3+1)}{2}=2+4$ and $\dfrac{4(4+1)}{2}=4+6$, we are done. QED
