This question already has an answer here:
Here is a geometric approach:
Let $\langle A, B \rangle = \mathbb{tr} (A^* B)$. It is straightforward to check that this is an inner product on the set of $p \times p$ matrices.
Let $V_1 = \{A\in V|\operatorname{Trace}(A)=0\}$. It is clear that $V_0 \subset V_1$; we need to show the reverse inclusion.
Note that $V_1 = \{ A | \langle I, A \rangle = 0 \}$, where $I$ is the identity. Also note that $V_0, V_1$ are both (closed) subspaces. To show inclusion it suffices to show that $V_0^\bot \subset V_1^\bot$. It is easy to see that $V_1^\bot = \mathbb{sp} \{I \}$.
Suppose $X \in V_0^\bot$. Then, for any matrices $A,B$, we have $\langle X, AB \rangle = \langle X, BA \rangle$. Let $E_{ij} = e_i e_j^T$, and choose $A= E_{ij}, B = E_{mn}$. Then we get $\langle X, AB \rangle = \langle X, E_{ij} E_{mn} \rangle = \delta_{jm} [X]_{in}$. Similarly, we get $\langle X, BA \rangle = \delta_{in} [X]_{mj}$. Consequently we have $\delta_{jm} [X]_{in} = \delta_{in} [X]_{mj}$ for all $i,j,m,n$. Now choose $j=m$, this simplifies to $ [X]_{in} = \delta_{in} [X]_{jj}$. If $i \neq n$, this gives $[X]_{in} = 0$, if $i = n$, this shows that all diagonal elements are equal, so we have $X = \lambda I$, for some $\lambda$. Consequently $X \in V_1^\bot$.
Take $B$ to be diagonal with distinct diagonal entries $b_1,\ldots, b_n$. Then the $ij$th entry of $AB-BA$ is $a_{ij}(b_i-b_j)$. Thus, with this particular $B$, the map $A\rightarrow AB-BA$ is injective on matrices $A$ with diagonal entries $0$. (And dimension count.)
Edit: and as in @copper.hat’s comment/question, this does not instantly address the diagonal matrices, and/but that reduces to the 2-by-2 case. Indeed, perhaps this is the more interesting part of the question. But/and the main point is that, with $x=\pmatrix{0&1\cr 0 & 0}$ and $y=\pmatrix{0&0\cr 1&0}$, the commutator is
$xy-yx=\pmatrix{1&0\cr 0&-1}$.
Extrapolating this gives the general diagonal things.