Define a new symmetric matrix variable
$$\eqalign{
X &= (S^TS)^{-1} \cr
dX &= -X\,\,d\big(S^T\!S\big)\,\,X \cr
&= -X\,\,(dS^TS+S^TdS)\,\,X \cr
&= -2\,X\,\,{\rm sym}(S^TdS)\,\,X \cr
}$$
Write the function using the Frobenius Inner Product and this new variable. Then finding the differential and gradient is pretty easy.
$$\eqalign{
f &= X:X \cr\cr
df &= 2\,X:dX \cr
&= -4\,X:X\,{\rm sym}(S^T\,dS)\,X \cr
&= -4\,X^3:{\rm sym}(S^T\,dS) \cr
&= -4\,{\rm sym}(X^3):S^T\,dS \cr
&= -4\,X^3:S^T\,dS \cr
&= -4\,SX^3:dS \cr\cr
\frac{\partial f}{\partial S} &= -4\,SX^3 \cr &= -4\,S(S^TS)^{-3} \cr
}$$