If you integrate the Gibbs equation $dU=TdS+ \sum_k Y_kdX_k$ with the assumption of $X_k$ and $U$ are extensive and $Y_k$ are intensive, then the function $U(S,X_k)$ are first order homogeneous and there follows that $U=TS+\sum_kY_kX_k$. This can be interpreted as the total internal energy of a body containing two terms $TS$ and $\sum_kY_kX_k$. The former $TS$ is the internal thermal energy, the latter is the internal everything else reflecting the various interactions the system may participate in, such as mechanical $X_1=V, Y_1=-p$, electrical $X_2=q_e, Y_2=\phi_e$, chemical, magnetic, etc. This has nothing to do with the Hamiltonian for $U$ is a static (timeless) energy while the Hamiltonian is a dynamic quantity so much so that even if $H$ is explicitly time independent it describes the time evolution of other dynamic quantities.