Mechanical energy is conserved when there are no non-conservative forces acting on the body. Examples are friction and elastic forces of stress in a body. These non-conservative forces convert mechanical energy to other forms of energy like heat and sound
Hope this makes sense