I claim that
The partial and total time derivatives of the hamiltonian are equal whenever the hamiltonian is evaluated on a solution to Hamilton's equations of motion.
For conceptual simplicity, let's restrict the discussion to systems with a two-dimensional phase space $\mathcal P$ with generalized coordinates $(q,p)$.
It's important to note what the total time derivative and partial time derivative mean in this context. In particular, recall that the Hamiltonian is a function that maps a pair consisting of a point $(q,p)$ in phase space and a point $t$ in time, to a real number $H(q,p,t)$. When we say that we are taking the partial time derivative of $H$, we mean that we are taking a derivative with respect to its last argument (in my notation). When we say that we are taking a total time derivative, we have in mind evaluating the phase space arguments of the Hamiltonian on a parameterized path $(q(t), p(t))$ in phase space, then then taking the derivative with respect to $t$ of the resulting expression, like this;
\begin{align}
\frac{d}{dt}\Big(H(q(t), p(t), t)\Big)
\end{align}
If we use the chain rule, we find that this total time derivative can be related to the partial time derivative of $H$ as follows:
\begin{align}
\frac{d}{dt}\Big(H(q(t), p(t), t)\Big) = \frac{\partial H}{\partial q}(q(t), p(t), t) \dot q(t) + \frac{\partial H}{\partial p}(q(t), p(t), t) \dot p(t) + \frac{\partial H}{\partial t}(q(t), p(t), t)
\end{align}
I have deliberately not abbreviated notation here to make explicit what exactly is going on so that there is no confusion. For example, the expression
\begin{align}
\frac{\partial H}{\partial q}(q(t), p(t), t)
\end{align}
means that we take the partial derivative of $H$ with respect to its first argument (which I labeled $q$), then then I evaluate the resulting function on $(q(t), p(t), t)$.
Now the question is, when are the total and partial time derivatives the same? Well, the relationship between them that we derived above shows that this happens if and only if the other stuff in the equation vanishes;
\begin{align}
\frac{\partial H}{\partial q}(q(t), p(t), t) \dot q(t) + \frac{\partial H}{\partial p}(q(t), p(t), t) \dot p(t)=0
\end{align}
Notice, now, that this equation definitely does not hold for a general path $(q(t), p(t))$ in phase space. I'll leave it to you to find a simple counterexample. So, for what paths does this relationship hold? Well, notice that this relationship is satisfied provided the path satisfies Hamilton's equations;
\begin{align}
\dot q(t) &= \frac{\partial H}{\partial p}(q(t), p(t), t) \\
\dot p(t) &= -\frac{\partial H}{\partial q}(q(t), p(t), t)
\end{align}
In other words, we have demonstrated the claim I started with.