Why is the electrostatic force felt in straight lines? When two positive charges are kept close, they get repelled in the direction of a line joining both the charges. Why is it so?

Also, why is the repulsion in a straight path?

In both the cases, the potential energy of the charge which gets repelled decreases. What makes it repel in a straight line such that the line passes through both charges?
 A: Maxwell's equations (along with the Lorentz force law) tell us that the force between two charges is radial (along the line connecting the charges).
You can also appeal to symmetry, which is related to R.W. Bird's point about conservation of angular momentum. Unless the charges have an inherent "orientation" associated with them (which might be in the form of angular momentum) or nature is "random" in the way it decides which way things move, there is no reason the charge on the right would move up or down.
A: Consider the case of two positively charged bodies, with gravitational forces similar to the electromagnetic repulsion, orbiting each other. The particles have to be travelling not on the same line to enter this system (eg opposite parallel paths), and we find the angular momentum for the orbiting situation comes from that, the ‘seesaw’ motion around their combined centre of mass.
Particles have electromagnetic properties which produce forces many orders of magnitude higher than gravitational, but all the forces momenta & potentials do always interact. There is no ‘pure’ electrostatic object. When you go beyond 2 bodies, and include magnetism, all kinds of strange things can happen. Have a look at pictures from cloud-chamber particle detectors.
Also, consider a delocalised electron - perhaps interacting with a hole in a semiconductor layer, to preserve having the same charges: It cannot be simplified like in your diagram, because the angular momentum of the electrons is 'smeared out’ through the conduction band.
This is about idealisations. The other idealisation, is nice neat spheres, like particles. What if they aren't: like say two negatively charged molecules, that have rotational energy. Changes in the rotation of the molecules, speeding up or slowing down, or changing the angle of tumbling, or adding momentum around another axis in the molecule, could give all different bounce directions. It's normal to deal with dynamics of spheres in particle mechanics, and gravitation. What that really means is asymmetries are small, compared to the size of the interaction being looked at. Quarks stop protons being points, Earth bulges in the middle and is lumpy. When something can be treated as a sphere, symmetry says it’s like all the forces act at the spheres centre, because that is where everything averages - but beware when that doesn’t hold.
Big picture, what you are asking about is symmetries, and it quickly gets you into our deepest ideas in physics. Why can particles only have curving interactions when they approach off-centre, and only linear interactions (where idealisations hold), is a deep question. Noether’s theorem relates conservation laws, like conservation of rotational momentum in this case (ie, if it starts at 0, both on same line, stays at zero), to continuous symmetries: these are generalisations of these 'little symmetries’, to the whole system, or to the universe itself. A lot of people think the total of important quantities like momentum and energy for the universe as a whole, will be zero. Occasional violations of symmetries/conserved quantities are key to the frontiers of physics, like charge-parity-time (CPT) violations, & CP violations that explain why there is more matter than antimatter.
Asking simple questions, and really digging until you get answers you are satisfied with, is key to really doing physics. Many important results came from people not satisfied with prevailing wisdom. If you really follow this question you will cover some of the deepest physics there is. Don’t let people fob you off! Keep digging. Keep asking simple questions, with tenacity.
A: Great question!
Perhaps you're familiar with the idea that the force on an object is the negative gradient of the potential energy created by that force*:
$-\vec{\nabla} PE(x,y,z) = \vec{F}(x,y,z)$
Now, imagine any slope. The gradient vector at any point on that slope points in the direction that you would step to increase you're altitude most quickly. The negative gradient vector does the opposite: it points in the direction that you would step to decrease you're altitude most quickly.
With this in mind, think about what this physics equation is really saying! The force on an object always points in the direction of travel that would most efficiently decrease it's potential energy.
So it's not JUST that the forces on the object want to get rid of it's potential energy, it's that (in this sense) they want to do it as efficiently as possible. This is why the positive charge wants to get away from the positive charge in a straight line: it wants to decrease it's potential energy as efficiently as possible.
*if the force is conservative, and here it is.
A: Just to elaborate on the symmetry argument - Let's suppose in your first diagram you are observing the two charges from the side and we assume, as you have done, that the repulsion direction is vertical and to the right. If we now observe the two charges from the top looking down, we are presented with the exact same situation as before and we would say the charge should now be repulsed horizontally and to the right. But that contradicts the direction we initially assumed - the repulsion cannot depend on how you look at the two charges. Continuing with this type of argument one can only conclude that the repulsion must be along the line connecting the two charges.
A: One answer is that forces are determined by the gradient of -U, where U is the potential energy.  Of course, that just raises the question of why that is so. I believe that the Principle of Least Action  prescribes that particles move along the gradient, but that similarly leads to the question of why particles are constrained to follow that. I believe that if you look at a Hamiltonian, the sum over histories of the paths other than following the gradient results in destructive interference, but I'm far from clear on that.
A: Following R.W. Bird answer:
Consider an isolated system of two particles:

Since system is isolated, angular momentum (and linear) is conserved.
I.e. $\vec\tau_{net}=\Sigma\space \vec r\times\vec F=0$
But clearly from figure $\vec\tau_{net}=\vec r\space\times\space\vec F_y\ne 0$
Thus as R.W. Bird noted, the system violates the conservation of angular momentum.
A: If the forces were not co-linear, the system would violate conservation of angular momentum.
A: You could dig deeper into this and probably find a very complicated explanation, however there is a simple reason:
Nobody knows why.
Yes, coloumb's law was empirical and it was observed how the charges behaved and then the law was derived. Most laws in classical physics are empirical and were observed at some point of time by really smart scientists and put into theory. Even the formula for the wavelength emitted for transition of an electron in an Hydrogen atom was discovered by trying to relate the numbers that were seen when the hydrogen spectrum was observed. This was accomplished by Balmer who was a teacher. Get used to this fact. If we could derive everything from scratch, why would there still be unanswered questions?
If this answer was helpful, take some time off to accept it and if you require any further information, do not hesitate to comment!
Edit:
Before you say that this isn't how stuff works and we can explain using this or that, remember that my point here is to tell that every theoretical concept requires some observational backing or assumption. Nothing can be derived from scratch. Nobel Prize Laureate for Physics Richard Peter Feynman has in his Feynman Lectures said that the universe is like a game, whose play we observe and based on our observation, we try to deduce the game's rules. This is the best explanation of the idea conveyed here. We did not make the game, we observe and deduce.
