Justification of the MHD energy principle for the stability of a confined toroidal plasma