Consider $E_{ij}$ the matrix with zero in every entry except where is takes value $1$ in the $(i,j)$-th component. We can write these as $E_{ij} = e_ie_j^T$ the product of $n \times 1$ and $1 \times n$ standard basis vectors and their transposes. Clearly, $e_i^T e_j = e_i \cdot e_j = \delta_{ij} = \begin{cases} 0 & i \neq j \\ 1 & i=j \end{cases}$. Consider then,
$$ E_{ij}E_{kl} = (e_ie_j^T)(e_ke_l^T) = e_i \delta_{jk}e_l^T = \delta_{jk}E_{il} $$
Any matrix may be written $A = \sum_{ij} A_{ij}E_{ij}$ for appropriate complex scalars $A_{ij}$. Likewise for $B$. Now plug these into the defining condition for $S$ and see what condition this forces on the components $A_{ij}$. Note:
$$ AB = \sum_{ijk} A_{ik}B_{kj}E_{ij} $$
But, $\text{trace}(C) = \sum_i C_{ii}$ hence
$$ \text{trace}(AB) = \sum_{ik} A_{ik}B_{ki} $$
On the other hand,
$$ \text{trace}(A)\text{trace}(B) = \sum_{i} A_{ii} \sum_k B_{kk} = \sum_{ik}A_{ii}B_{kk} $$
Therefore, in general, $f(A,B)=0$ yields the condition that follows as $n\text{trace}(AB)-\text{trace}(A)\text{trace}(B) = \text{trace}(nAB)-\text{trace}(A)\text{trace}(B)$
$$ 0 = \sum_{ik} (nA_{ik}B_{ki} -A_{ii} B_{kk}) \qquad \star $$
We want to characterize all $A$ such that $f(A,B)=0$ for all $B$. Therefore, we can choose particular $B$ as to simplify the condition above. For example $B=E_{pq}$ has $\text{trace}(B)=\delta_{pq}$ and $B_{ij} = \delta_{pi}\delta_{qj}$ and it follows that $\star$ reduces to:
$$ 0 = \sum_{ik} (nA_{ik}\delta_{pk}\delta_{qi} -A_{ii}\delta_{pk}\delta_{qk} )$$
Therefore, keep in mind $p,q$ are free indices here,
$$ 0 = nA_{qp} -\text{trace}(A)\delta_{pq} $$
hence, swapping $p$ with $i$ and $q$ with $j$ we find
$$ A_{ij} = \frac{1}{n}\text{trace}(A)\delta_{ij}$$
Thus, if $f(A,B)=0$ for all $B$ then
$$ A = \sum_{ij} A_{ij}E_{ij} = \sum_{ij}\frac{1}{n}\text{trace}(A)\delta_{ij}E_{ij} =\frac{1}{n}\text{trace}(A) \sum_i E_{ii} = \frac{\text{trace}(A)}{n}I.$$
Thus $S = span(I)$.
So, I bet you're correct, I suspect you could find this from a more clever line of reasoning. Truth is that I happen to enjoy this sort of calculation.