I found a formula in a book
$ \sum_{n=1}^{\infty} \frac{(\cos (\pi n s) - \cos (\pi n s'))^2}{n^2} = \frac{\pi^2}{2} |s-s'|$
but no explanation of where it came from. I checked that it holds true numerically. I wondered whether this series has a name and where could I find more information about it. It looks like some variant of the Basel problem, but other than that I'm clueless. Thanks!
Upon expanding the square, the numerator comes down to
$$(\cos(\pi ns)-\cos(\pi ns'))^2=\cos^2(\pi ns)+\cos^2(\pi ns')-2\cos(\pi ns)\cos(\pi ns')$$
Using trigonometric identities, this further reduces down to
$$=\frac12\cos(2\pi ns)+\frac12\cos(2\pi ns')+1-\cos(\pi n(s+s'))-\cos(\pi n(s-s'))$$
We may then apply the Clausen function to deduce that (refer to formula 7)
$$\sum_{n=1}^\infty\frac{\frac12\cos(2\pi ns)+\frac12\cos(2\pi ns')+1-\cos(\pi n(s+s'))-\cos(\pi n(s-s'))}{n^2}\\=\frac12\operatorname C_2(2\pi s)+\frac12\operatorname C_2(2\pi s')+\frac{\pi^2}6-\operatorname C_2(\pi(s+s'))-\operatorname C_2(\pi(s-s'))\\=\pi^2\left(\frac1{12}-\frac12s+\frac12s^2+\frac1{12}-\frac12s'+\frac12s'^2+\frac16-\frac16+\frac12(s+s')-\frac14(s+s')^2-\frac16+\frac12(s-s')-\frac14(s-s')^2\right)\\=\frac{\pi^2}2\left(s-s'\right)$$
assuming that $0\le s\le1$ and $0\le s'\le1$.