The energy function is not always equivalent to the energy of the system. Consider the case when it happens to be: Suppose we have lagrangian given by
$$\mathcal{L}= \mathcal{L}_0+\mathcal{L}_1+\mathcal{L}_2 $$
where
$$\mathcal{L}_0=\mathcal{L}_0(q,t)$$, $$\mathcal{L}_1=\sum_{i}b_i\dot{q}_i$$ and $$\mathcal{L}_2=\sum_{i,j}c_{ij}\dot{q}_i\dot{q}_j$$
In this case, the energy function $h$ can be calculated as
$$ \frac{\partial \mathcal{L}}{\partial \dot{q}_i} = \frac{\partial }{\partial \dot{q}_i}(\mathcal{L}_0+\mathcal{L}_1+\mathcal{L}_2)$$
$$ =b_i + \sum_{j} c_{ij}\dot{q}_j $$
$$ \dot{q}_i \frac{\partial \mathcal{L}}{\partial \dot{q}_i} =\sum_{i}b_i\dot{q}_i +\sum_{i}\sum_{j}c_{ij}\dot{q}_i\dot{q}_j $$
$$ \dot{q}_i \frac{\partial \mathcal{L}}{\partial \dot{q}_i}=\mathcal{L}_1+2\mathcal{L}_2 $$
Thus $$ h =\mathcal{L}_2-\mathcal{L}_0 $$
The first term $\mathcal{L}_0$ is a function of co-ordinating $q$ and thus can be regarded as Potential energy. The third term $\mathcal{L}_2$ is a general term for kinetic energy and thus
$$ E = T+V $$
Thus In this special form of lagrangian, the Energy function is the same as Energy.
Now why this happens can be understood with the following example.
Suppose a bead on a rotating wire with anglure velocity $\omega$. The langrangian system is given by
$$ \mathcal{L}=\frac{1}{2}m(\dot{r}^2+r^2\omega^2) $$
The energy for the system is $$h=\frac{1}{2}m(\dot{r}^2+r^2\omega^2) $$
Energy function for the system given by
$$E = \frac{1}{2}m(\dot{r}^2-r^2\omega^2) $$
Which is of course not the same as the energy of the system. So you see when there is the pumping of energy through the constraint energy don't be com anymore but as lagrangian is still time-independent the energy function is still COM.