Here are two variations to calculate the residue of $f$ at $x=i$. We already know the pole of $f$ at $x=i$ is of order $2$. A common way is to use the
Limit formula for higher order poles:
We obtain
\begin{align*}
\color{blue}{\mathrm{res}_{x=i}f(x)}&=\mathrm{res}_{x=i}\frac{x^2}{\left(1+x^2\right)}\\
&=\lim_{x\to i}\frac{d}{dx}\left((x-i)^2f(x)\right)\\
&=\lim_{x\to i}\frac{d}{dx}\left(\frac{x^2}{(x+i)^2}\right)\\
&=\lim_{x\to i}\frac{2ix}{(x+i)^3}\\
&=\frac{2i^2}{(2i)^3}\\
&\,\,\color{blue}{=-\frac{1}{4}i}\tag{1}
\end{align*}
It is somewhat more cumbersome, but also not so difficult, to calculate the remainder of $f$ at $x=i$ by consequent expansion at $x=i$.
Manual expansion in terms of $(x-i)$:
We start with
\begin{align*}
f(x)&=\frac{x^2}{\left(1+x^2\right)^2}=\frac{x^2}{(x+i)^2(x-i)^2}\\
&=\frac{(x-i+i)^2}{(x-i+2i)^2(x-i)^2}\\
&=\frac{(x-i)^2+2i(x-i)-1}{(2i)^2\left(1+\frac{x-i}{2i}\right)^2(x-i)^2}\\
&=-\frac{1}{4}\frac{1}{\left(1+\frac{x-i}{2i}\right)^2}
+\frac{1}{2i(x-i)}\,\frac{1}{\left(1+\frac{x-i}{2i}\right)^2}\\
&\qquad+\frac{1}{4(x-i)^2}\,\frac{1}{\left(1+\frac{x-i}{2i}\right)^2}\tag{2}
\end{align*}
The expansion of the square of the geometric series in (2) gives
\begin{align*}
\frac{1}{\left(1+\frac{x-i}{2i}\right)^2}
&=\left(1-\frac{x-i}{2i}+\cdots\right)\left(1-\frac{x-i}{2i}+\cdots\right)\\
&=1-\frac{x-i}{i}+\mathrm{higher\ order\ terms}\tag{3}
\end{align*}
We derive from (2) and (3)
\begin{align*}
\color{blue}{\mathrm{res}_{x=i}f(x)}=0+\frac{1}{2i}+\frac{1}{4}\left(-\frac{1}{i}\right)\,\,\color{blue}{=-\frac{1}{4}i}
\end{align*}
in accordance with (1).