I know this question has been answered here for example but I want to make emphasis in a new aspect. Consider the variation of the metric determinant $\delta g$ with respects to variations of the metric $g_{\mu\nu}$. A customary way to find $\delta g$ is to consider the matrix identity $$\ln(\det A)=\mathrm{Tr}(\ln A).$$
If we take $A$ as the metric $g_{\mu\nu}$ we would get $\ln(g)=\mathrm{Tr}(\ln g_{\mu\nu})$. Now, when varying this we get $$\delta g=g \, \delta[Tr(\ln g_{\mu\nu})]=g\, \delta [\mathrm{Tr}(A_{\mu\nu})], $$ where I just called $A_{\mu\nu}=\ln g_{\mu\nu}$.
Calculations of $\delta g$ usually assume that $\delta$ and $\mathrm{Tr}$ commute, which makes sense if you regard $Tr$ as a sum of diagonal elements of a matrix. However, that could be done if the densor were of the form $A^\mu_\nu$, which is not the case here. So then, I would write it as $$\delta g=g\, \delta(g^{\mu\nu}A_{\mu\nu}).$$
This is the critical step I'm trying to understand because when I write it this way I should use sort of Leibniz rule for the variation and an extra term appears $g\, A_{\mu\nu}\delta g^{\mu\nu}$ with respect to the actual answer. I just want to know where I go wrong when managing tensors.