Relative Energy for the Korteweg Theory and Related Hamiltonian Flows in Gas Dynamics