Let $B,C,D \in \mathbb{R}^{n\times n}$.
If $\forall D \in \mathbb{R}^{n\times n}$; tr($BD$) = tr($CD$), does it hold that $B=C$?
I was attempting to prove it by writing the double sums of the definition of trace, but can't reach a suitable change of indexes.
Is there a shorter alternative of proving this by building some $D_i$ matrices and iteratively doing $BD_i$ and $CD_i$?
Here is a nice way of rephrasing your question. Indeed, consider two matrices $B$ and $C$ of the same dimension. Then if for all $D$ of the same dimension, we have $\operatorname{tr}BD =\operatorname{tr} CD$, then by linearity of the trace, we have $\operatorname{tr}((B-C)D) = 0$ for all $D$. Write $(B-C) = M$, then $\operatorname{tr}MD = 0$ for all $D$.
Therefore, the question of whether $B=C$ or not, boils down to whether $M=0$ or not. Indeed, the answer to the question is that $M=0$ if the above happens.
To see this, suppose for contradiction that $M_{ij} \neq 0$ for some $1 \leq i,j \leq n$. Then, let $D$ be the matrix such that $D_{ji} = 1$ and zero everywhere else. Then, calculate $MD$. We have : $(MD)_{kl} = \sum_{m} M_{km}D_{ml}$ by matrix multiplication. This is zero whenever $l \neq i$, and if $l = i$ then $(MD)_{ki} = M_{kj}$ for all $k$, by the fact that $m=i$ is the only non-zero term in the summation in that case.
But then, the trace of $MD$ is exactly $MD_{ii}$ which is the only nonzero entry along the diagonal, and this is equal to $M_{ij}$, which is non-zero.
So, we have found a non-zero matrix $D$ such that the trace of $MD$ is non-zero. It follows that $M = 0$ if there is no such non-zero $D$.