It seems to have escaped attention that this sum may be evaluated
using harmonic summation techniques which can be an instructive
exercise and usually succeeds on Fourier series. Here is an opportunity
to contribute to an interesting, diverse and visually appealing series
of posts.
Introduce $S(x)%$ given by
$$S(x) = \sum_{n\ge 1} \frac{1}{n}\cos(nx).$$
The sum term is harmonic and may be evaluated by inverting its Mellin
transform.
Recall the harmonic sum identity
$$\mathfrak{M}\left(\sum_{k\ge 1} \lambda_k g(\mu_k x);s\right) =
\left(\sum_{k\ge 1} \frac{\lambda_k}{\mu_k^s} \right) g^*(s)$$
where $g^*(s)$ is the Mellin transform of $g(x).$
In the present case we have
$$\lambda_k = \frac{1}{k}, \quad \mu_k = k
\quad \text{and} \quad
g(x) = \cos(x).$$
We need the Mellin transform $g^*(s)$ of $g(x)$.
Now the Mellin transform of $\cos(x)$ was computed at this MSE link
and found to be $$\Gamma(s) \cos(\pi s/2)$$
It follows that the Mellin transform $Q(s)$ of the harmonic sum
$S(x)$ is given by
$$Q(s) = \Gamma(s)\cos(\pi s/2) \zeta(s+1)
\quad\text{because}\quad
\sum_{k\ge 1} \frac{\lambda_k}{\mu_k^s} =
\sum_{k\ge 1} \frac{1}{k} \frac{1}{k^s}
= \zeta(s+1)$$
for $\Re(s) > 0.$
The Mellin inversion integral here is
$$\frac{1}{2\pi i} \int_{1/2-i\infty}^{1/2+i\infty} Q(s)/x^s ds$$
which we evaluate by shifting it to the left for an expansion about
zero.
The zeros of the cosine term at the negative odd integers cancel the
poles of the gamma function at those values. No additional cancelation
is gained from the trivial zeros of the zeta function term
$\zeta(s+1)$ as these are (also) at the odd negative integers to the
left of $-1.$ This leaves the pole from the zeta term at $s=0$ and the
poles of the gamma function at negative even integers to the left of
zero.
Note that in a neighborhood of zero, we have
$$\frac{1}{x^s} = 1 - \log(x) s + \frac{1}{2} \log^2(x) s^2
+ \sum_{q\ge 3} \frac{(-1)^q}{q!} \log^q(x) s^q$$
and
$$\zeta(s+1) = \frac{1}{s} + \gamma - \gamma_1 s
+ \sum_{q\ge 2} \frac{(-1)^q}{q!} \gamma_q s^q$$
and
$$\Gamma(s) = \frac{1}{s} - \gamma
+ \left(\frac{\gamma^2}{2}+\frac{\pi^2}{12}\right) s + \cdots$$
and finally
$$\cos(\pi s/2) = 1 - \frac{\pi^2}{8} s^2
+ \frac{\pi^4}{384} s^4 +
\sum_{q\ge 3} (-1)^q \frac{\pi^{2q}}{2^{2q}\times (2q)!} s^{2q}.$$
Collecting the contributions to $1/s$ we get
$$-\log(x)s \times \frac{1}{s} \times \frac{1}{s} \times 1
+ 1\times \frac{1}{s} \times -\gamma
+ 1\times \gamma \times \frac{1}{s}$$
and hence
$$\mathrm{Res}\left(Q(s)/x^s; s=0\right) = -\log x.$$
Fortunately the residues from the remaining poles are simple to compute and summing all
contributions we get
$$\sum_{q\ge 1} \mathrm{Res}\left(Q(s)/x^s; s=-2q\right) =
\sum_{q\ge 1} \frac{1}{(2q)!}
(-1)^q \times x^{2q} \times -\frac{B_{2q}}{2q}.$$
This sum is in fact
$$-\sum_{q\ge 1} \frac{(ix)^q}{q!} \frac{B_q}{q}
+ ix \times -\frac{1}{2}.$$
Recall that
$$\sum_{q\ge 1} B_q \frac{t^q}{q!} =
-1 + \frac{t}{e^t-1}$$
so that
$$\sum_{q\ge 1} B_q \frac{t^{q-1}}{q!} =
-\frac{1}{t} + \frac{1}{e^t-1}$$
and hence
$$\sum_{q\ge 1} B_q \frac{t^q}{q\times q!} =
-\log(t) + \log(e^t-1)- t.$$
This is $\sim -1/2 \times t$ in a neighborhood of zero so we can be
sure no spurious constant has appeared during the integration.
We return to our collection of residues and finally obtain (setting $t=ix$)
$$\log(ix) - \log(e^{ix}-1)+ ix - \frac{1}{2} ix -\log x
= -\log(e^{ix}-1) + \log i + \frac{1}{2} ix
\\= -\log e^{ix/2} -\log(e^{ix/2}-e^{-ix/2}) + \log i + \frac{1}{2} ix
\\= -\log(2i\sin(x/2)) + \log i
= -\log(2\sin(x/2)).$$
This holds for $x$ in $(0,2\pi).$ Observing that $S(x)$ is periodic
with period $2\pi$ and even we get the end result
$$-\log|2\sin(x/2)|.$$