The potential energy of a charged capacitor is given by U=
Q2
2C
. When a dielectric slab is introduced between the plates the energy is given by
Q2
2KC
where K is the dielectric constant. Again, when the dielectric slab is removed slowly its energy increases to initial potential energy. Thus, work done is zero.