How did Euler prove this identity?
According to Wikipedia (https://en.wikipedia.org/wiki/Basel_problem), Euler was the first to give a representation of the sine function as an infinite product: $$(*) \hspace{2cm}\sin (\pi \alpha)=\pi \alpha \prod\limits_{n=1}^{\infty}(\frac{n^2-\alpha^2}{n^2}),$$ which was formally proved by Weierstrass about 100 years later.
Now taking "$\ln$" on by sides of (*) gives $$\ln(\sin (\pi \alpha))=\ln(\pi \alpha)+ \sum \limits_{n=1}^{\infty} \ln (\frac{n^2-\alpha^2}{n^2}),$$ and after taking derivatives on both sides we arrive at
$$\sum_{n=1}^{\infty}\frac{1}{n^2-\alpha^2}=\frac{1}{2\alpha^2}-\frac{\pi}{2\alpha\tan\pi\alpha}.$$
For the partial fraction decomposition of the cotangent $$\pi \cot \pi z = \frac{1}{z} + \sum_{n\ge 1}\left( \frac{1}{z-n} + \frac{1}{z+n}\right) = \lim_{k\to\infty} \sum_{n=-k}^k \frac{1}{z-n}$$ hence \begin{align*} \sum_{n=1}^\infty \frac{1}{n^2-\alpha ^2} &= \lim_{k\to\infty}\sum_{n=1}^k \frac{1}{n^2-\alpha^2}\\ &= -\frac{1}{2\alpha}\lim_{k\to\infty} \sum_{n=1}^k \frac{1}{\alpha-n} + \frac{1}{\alpha+n}\\ &= -\frac{1}{2\alpha}\lim_{k\to\infty} \left(-\frac{1}{\alpha} +\sum_{n=-k}^k \frac{1}{\alpha-n}\right)\\ &= -\frac{1}{2\alpha}\left(\pi \cot \pi \alpha - \frac{1}{\alpha}\right)\\ &= \frac{1-\pi \alpha\cot \pi \alpha}{2\alpha^2}\\ &=\frac{1}{2\alpha^2}-\frac{\pi}{2\alpha\tan\pi\alpha} \end{align*}