[EDIT: Based on the discussion from the comments under this and Qmechanic's answer, it's worth noting that the following derivation only applies to this example because it is one dimensional. Further clarification and corrections have been added throughout this answer and in a final edit at the bottom.]
One minor technicality before I begin: The energy is a function of $x$ and $\dot x$, while the Hamiltonian is a function of $q=x$ and $p=m\dot x$. So they are different, technically.
Consider the chain rule for the two quantities (i.e. Energy and Hamiltonian):
$$
\frac{dH}{dt}=\frac{d q}{d t}\frac{\partial H}{\partial q}+\frac{d p}{d t}\frac{\partial H}{\partial p}
\\
\frac{dE}{dt}=\frac{d x}{d t}\frac{\partial E}{\partial x}+\frac{d \dot x}{d t}\frac{\partial E}{\partial \dot x}
$$
You know that the second equation must be zero since energy is conserved (i.e. $\frac{dE}{dt}=0$). But have you ever considered why you know that energy is conserved? The answer is (of course) because it was designed that way.
Here are some basic assumptions: (i) Newton's 2nd Law is true (i.e. $F=ma$) and (ii) the force is conservative (i.e. $F=-\frac{\partial E}{\partial x}$). Using these two facts and the chain rule above:
$$
\frac{dE}{dt}=\frac{d x}{d t}\frac{\partial E}{\partial x}+\frac{d \dot x}{d t}\frac{\partial E}{\partial \dot x}\\
\frac{dE}{dt}=\frac{d x}{d t}(-F)+(a)\frac{\partial E}{\partial \dot x}\\
\frac{dE}{dt}=\frac{d x}{d t}(-ma)+(a)\frac{\partial E}{\partial \dot x}
$$
Now, suppose you want this quantity to be conserved. In that case:
$$
0=\frac{d x}{d t}(-ma)+(a)\frac{\partial E}{\partial \dot x}\\
\frac{\partial E}{\partial \dot x}=m\dot x\\
\therefore E = \frac{1}{2}m\dot{x}^2 + U(x)
$$
So if Newton's Second Law is true and energy is conserved, then energy must be defined in the usual way. Or, by reversing the derivation and assuming that the usual energy definition applies and that it is conserved (and that $\dot x \neq 0$), then you can deduce Newton's Second Law. (This is the derivation performed in the question.)
What if you want the Hamiltonian to be conserved? In that case, since we have assumed that $q=x$ and $p=m\dot x$ and since we want the Energy and the Hamiltonian to both represent the same quantity, we know that $F = -\frac{\partial H}{\partial q}$, and since Newton's Second Law tells us that $F=\frac{d p}{d t}$, we conclude that $\frac{d p}{d t}=-\frac{\partial H}{\partial q}$ (i.e. the first of Hamilton's Equations).
Now, let's require the Hamiltonian to be conserved:
$$
0=\frac{d q}{d t}\frac{\partial H}{\partial q}+\frac{d p}{d t}\frac{\partial H}{\partial p}\\
0=\frac{d q}{d t}(-\frac{d p}{d t})+\frac{d p}{d t}\frac{\partial H}{\partial p}\\
\therefore \frac{d q}{d t}=\frac{\partial H}{\partial p}
$$
So, by assuming Newton's Second Law and that the Hamiltonian is conserved (and $\frac{dp}{dt}\neq 0$), we deduce Hamilton's Equations. And just as before, the derivation is reversible. If you start by assuming Hamilton's Equations, then it is guaranteed that the Hamiltonian with be conserved.
Conclusion: If Hamilton's Equations are true (under the usual assumptions of conservative forces, no time dependence, etc.), then the Hamiltonian is conserved. And, in one dimension (plus some basic assumptions), the converse is also true: Conservation of the Hamiltonian implies Hamilton's Equations. But in general: $\{\frac{d q_i}{d t}=\frac{\partial H}{\partial p_i},\frac{d p_i}{d t}=-\frac{\partial H}{\partial q_i} \} \implies \frac{dH}{dt}=0$, but not vice versa.
EDIT: When we discuss classical mechanics, we are really talking about trajectories. In the absence of non-conservative forces, if a trajectory obeys Newton's Second Law (resp. Hamilton's Equations), then it will conserve the usual definition of energy (resp. the Hamiltonian). However, the converse is not in general true. A trajectory that conserves energy might be highly unphysical. Take as an example a ball hanging in mid-air: its energy is constant, but that's not how gravity is supposed to work.
The derivation in the original question implicitly assumed that $\dot x \neq 0$ when it was cancelled out from both terms. This additional assumption is all that is required in one dimension to derive Newton's Second Law, but in higher dimensions, more and more perverse trajectories can be invented which will conspire to conserve energy while still violating the basic precepts of classical trajectories.