When we derive the equation for potential energy between two nearby point charges the final result says if both charges are of similar polarity then only we take potential energy of the system as positive. Now in case of a capacitor we have two oppositely charged plates kept close to each other but electrostatic potential energy of the capacitor is not taken as negative.
3 Answers
Whenever you think about potential, do not think of it as a value at one place. Rather, think of it as the difference between the value at one place and the value at another. When we say "the potential at distance $r$ from a charge is $q/4\pi\epsilon_0 r$," that should be understood as a shorthand for "the difference between the potential at $r$ and the potential at infinity is $q/4\pi\epsilon_0 r$." When we say the potential energy for a system of two charges is $q_1 q_2/4\pi\epsilon_0 r$, that is a shorthand for the corresponding statement about a difference in potential energy. It is really saying that in order to move the charges from infinitely far apart to $r$ apart then you have to do the work: the energy you have to provide is $q_1 q_2/4\pi\epsilon_0 r$. When this is negative (when the charges have opposite signs) then it means you gain the energy.
For the capacitor the relevant question is, do I have to provide energy to the capacitor in order to build up the charge there, compared to the case where there is no charge? The answer is yes, you have to provide energy. Ultimately the reason is that there is an electric field inside the capacitor, and that is where the energy is stored. But if you want to think of it also in terms of pushing charge onto the capacitor then what is going on is that charge has to be pulled away from one plate, and pushed onto the other. If the capacitor already has a non-zero stored charge, then on its journey the positive charge moving from one plate to the other has to go from a place at lower potential to a place at higher potential. So to make it go on this journey, energy has to be provided.
Now what really happens is that a negative charge (carried by electrons) moves in the other direction. But it is helpful to think of it in terms of moving a positive amount of charge in order to avoid confusion about the signs.
The potential energy is positive because we're considering it relative to a "base case" or reference condition where the positive and negative charges are right next to each other in the same piece of metal. Rather than to a base case where the charges are infinitely separated.
We do that because in real materials it's very common for there to be equal amounts of positive and negative charge in close proximity, and relatively uncommon for the charge to be separated. Practically it's only possible to completely separate the charge in a material with a very light atom like hydrogen.
It costs energy to bring a capacitor from an uncharged to a charged state, and to bring to like charges (+) and (+) together. This energy is released spontaneously in the reverse process if the force keeping it in that state is removed (i.e. the point charges are released, or the capacitor is presented with a current path with no applied voltage). That is why these energies are positive.
In contrast, it costs no energy to bring two unlike charges (+) and (-) together. It happens spontaneously. But it costs energy to reverse the process and separate them. Thus the potential energy here is negative. This is the same for gravity as well, another attractive force.