Series $\sum_{n=1}^{\infty}\frac{\cos(nx)}{n^2}$
See the results posted here, where I show that
$$\sum_{n=-\infty}^{\infty} \frac{\sin^2{a n}}{n^2} = \pi a$$
when $a \in (0,\pi)$. Now, use the fact that
$$\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}$$
and let $S$ be the sum in question. Then
$$\frac{\pi^2}{6} - S = \sum_{n=1}^{\infty} \frac{1-\cos{n x}}{n^2} = 2 \sum_{n=1}^{\infty} \frac{\sin^2{n x/2}}{n^2}$$
Rewrite the last sum as
$$2 \sum_{n=1}^{\infty} \frac{\sin^2{n x/2}}{n^2} = \sum_{n=-\infty}^{\infty} \frac{\sin^2{n x/2}}{n^2} - \left ( \frac{x}{2} \right )^2 = \pi \frac{x}{2} - \frac{x^2}{4}$$
Then
$$\frac{\pi^2}{6} - S = \pi \frac{x}{2} - \frac{x^2}{4} \implies S = \frac{x^2}{4} - \pi \frac{x}{2} + \frac{\pi^2}{6}$$
as was to be shown.
The sum term $$T(x) = \sum_{n\ge 1}\frac{\cos(nx)}{n^2} = x^2 \sum_{n\ge 1}\frac{\cos(nx)}{(xn)^2}$$ is harmonic and may be evaluated by inverting it's Mellin transform. Put $$S(x) = \sum_{n\ge 1}\frac{\cos(nx)}{(xn)^2}$$ and 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 = 1, \quad \mu_k = k \quad \text{and} \quad g(x) = \frac{\cos x}{x^2}.$$ We need the Mellin transform $g^*(s)$ of $g(x)$ which is $$\int_0^\infty \frac{\cos x}{x^2} x^{s-1} dx = \int_0^\infty \cos x \times x^{(s-2)-1} dx.$$ Now the Mellin transform of $\cos(x)$ was computed at this MSE link and found to be $$\Gamma(s) \cos(\pi s/2)$$ and therefore $$g^*(s) = \Gamma(s-2) \cos(\pi (s-2)/2) = \Gamma(s-2) \cos(\pi s/2 - \pi) = -\Gamma(s-2) \cos(\pi s/2).$$ Therefore the Mellin transform $Q(s)$ of $S(x)$ is given by $$ Q(s) = -\Gamma(s-2) \cos(\pi s/2) \zeta(s) \quad\text{because}\quad \sum_{k\ge 1} \frac{\lambda_k}{\mu_k^s} = \zeta(s).$$ Therefore the Mellin inversion integral for an expansion about zero is $$\frac{1}{2\pi i} \int_{5/2-i\infty}^{5/2+i\infty} Q(s)/x^s ds$$ which we evaluate in the left half-plane $\Re(s)<5/2.$ The cosine term cancels the poles of the gamma function term at odd negative integers and the zeta function term the poles at even negative integers. We are left with just three poles. $$\begin{align} \mathrm{Res}(Q(s)/x^s; x=2) & = \frac{\pi^2}{6x^2} \\ \mathrm{Res}(Q(s)/x^s; x=1) & = -\frac{\pi}{2x} \quad\text{and}\\ \mathrm{Res}(Q(s)/x^s; x=0) & = \frac{1}{4}. \end{align}$$ Hence in a neighborhood of zero, $$S(x) = \frac{\pi^2}{6x^2} -\frac{\pi}{2x} +\frac{1}{4}.$$ Using $T(x) = x^2 S(x)$ this finally yields in a neigborhood of zero that $$T(x) = \frac{\pi^2}{6} -x\frac{\pi}{2} +x^2\frac{1}{4}.$$ Since $T(x)$ is periodic with period $2\pi$ the interval this approximation is good in $(0,2\pi).$
There is a theorem hiding here, namely that certain Fourier series can be evaluated by inverting their Mellin transforms which is not terribly surprising and which the reader is invited to state and prove.
$\newcommand{\bbx}[1]{\,\bbox[8px,border:1px groove navy]{\displaystyle{#1}}\,} \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace} \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack} \newcommand{\dd}{\mathrm{d}} \newcommand{\ds}[1]{\displaystyle{#1}} \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,} \newcommand{\ic}{\mathrm{i}} \newcommand{\mc}[1]{\mathcal{#1}} \newcommand{\mrm}[1]{\mathrm{#1}} \newcommand{\pars}[1]{\left(\,{#1}\,\right)} \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}} \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,} \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}} \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$ \begin{align} \sum_{n = 1}^{\infty}{\cos\pars{nx} \over n^{2}} & = \Re\sum_{n = 1}^{\infty}{\pars{\expo{\ic x}}^{n} \over n^{2}} = \Re\,\mrm{Li}_{2}\pars{\exp\pars{2\pi\ic\,{x \over 2\pi}}} \\[5mm] & = -\,{1 \over 2}\,{\pars{2\pi\ic}^{2} \over 2!}\,\mrm{B}_{2}\pars{x \over 2\pi} \label{1}\tag{1} \end{align} where we used Jonquiere Inversion Formula. $\ds{\,\mrm{B}_{n}\pars{x}}$ is a Bernoulli Polynomial. $\ds{\,\mrm{B}_{2}\pars{x} = x^{2} - x + {1 \over 6}}$
\eqref{1} becomes: $$ \bbx{\ds{% \sum_{n = 1}^{\infty}{\cos\pars{nx} \over n^{2}} = {x^{2} \over 4} - {\pi x \over 2} + {\pi^{2} \over 6}}}\,,\quad \left\{\begin{array}{rcl} \ds{x \in \left[0,2\pi\right)} & \mbox{if} & \ds{\Im\pars{x} \geq 0} \\[2mm] \ds{x \in \left(0,2\pi\right]} & \mbox{if} & \ds{\Im\pars{x} < 0}\\ & \end{array}\right. $$