When the capacitor is not connected to anything, the free charge on its plates have nowhere to move to so it remains the same. When the dielectric is inserted between the plates, the positive plate attracts the negative ends of the dipolescharges towards itself and vice versa, aligning them with. This causes a net displacement of charge and thus polarizes the dielectric in the same direction as the applied electric field. This produces accumulations of bound charge at either end that are of opposite sign as the free charge. This decreases the total charge density at the plates and therefore the potential difference.
On the other hand, an ideal battery by definition maintains a certain potential difference between its terminals. Therefore, when the dielectric is inserted, it will do additional work by increasing the charge until the potential difference is reached.