Lagrangian formalism does not involve forces that doesn't come from a potential and Hamiltonian formalism says that even though energy is not conserved due to a force like this, the Hamiltonian is conserved. My question is that if we see that the Lagrangian is not conserved in a process due to a external force, how can it be that the Hamiltonian is conserved?
It is called Jacobi's theorem. The symplest situation is that where the Lagrangian $T-U$ is referred to an inertial reference frame $I$, while the used Lagrangian coordinates are at rest with a different reference frame $I'$, rotating with fixed angular velocity with respect to the former. If this Lagrangian does not depend explicitly on time, the associated Hamiltonian is conserved, but it is the mechanical energy defined respect to the rotating reference frame $I'$ and not that in $I$, that is not conserved because one has to supply energy to maintain the rotation uniformly.