Let us charge a capacitor and disconnect it from the battery. Let the capacitance, charge and voltage of the capacitor be C, Q and V respectively. Now do some work and reduce the distance of the plates of the capacitor and make it half of the original distance. What are the energies stored in the capacitor before and after the reduction of distance? The energies can be calculated as square(Q)/2C and square(Q)/4C respectively. Where has the energy gone from the capacitor?