The potential energy of a charge which is brought near another charge (of the same sign) from infinity by applying an external force which is equal to the electrostatic force of repulsion. The potential energy has an inverse dependence with distance. Therefore, the potential energy increases as we bring the charge closer. But where is this energy coming from? Since the work done by the external force is equal to the negative work done by the electrostatic force. Only way I can explain is the kinetic energy decreases as the charge becomes closer and potential energy increases, keeping the total energy constant. Am I correct or is there is some other explanation?
The only requirement is that there is no change in kinetic energy of the charge when moving between the two points. This can be accomplished by having the external force equal the electric field force so that the velocity of the charge is constant between the two points.
If the charge begins at rest, then the external force may need to be briefly greater than the force of the electric field to get the charge moving and briefly less than the force of the field just prior reaching the second point to bring it back to rest, for a zero net charge in kinetic energy.
The gravitational analogy is lifting an object a certain height beginning and ending at rest
As far as where the potential energy comes from, it ultimately comes from the external agent. It does positive work giving energy to the charge and the field does an equal amount of negative work taking the energy given to the charge by the external agent and storing it as electrical potential energy in the charge/electric field system.
Hope this helps.