How the electrostatic energy of attraction is minimum in the ground state of an atom?
What you are missing is that the electrostatic potential energy between the nucleus and the electrons is negative. “Minimum” here means “as negative as possible”.
For example, for hydrogen the electrostatic PE in the ground state is -27.2 eV. In the first excited state it is -6.8 eV.