At first, there is a potential difference between the two plates of the capacitor equal to the potential difference between the two battery terminals. This causes electrons to build up on one of the plates making that one more negatively charged and the other plate more positively charged, due to the negatively charged electrons repelling the electrons on the other plate.
Eventually, all the electrical energy is stored as electrostatic potential energy in the form of an electric field in the capacitor. It stops charging once the plates have equal but opposite charges.