The capacitor is a charge storage device work has to be done to store the charges in a capacitor. This work done is stored as electrostatic potential energy in the capacitor.
Let q be the charge and V be the potential difference between the plates of the capacitor. If dq is the additional charge given to the plate, then work done is, dw=Vdq.
dw=qCdq (∴V=qC)
Total work done to charge a capacitor is
w=∫dw=∫q0qCdq=12q2C
This work done is stored as electrostatic potential energy (U) in the capacitor.
U=12q2C=12CV2 (∴q=CV)
U=q22C. Hence proved.