why the force is exerted only along its length
Let's make two assumptions:
- The rod is very "light"
- Nothing interacts with it except the balls at the ends.
If one ball tries to move closer or farther from the other ball, the rod would either have to change length, or it would have to accelerate the other ball to move in the same direction. So forces along the rod are transmitted to the other ball.
But if one of the balls tries to move perpendicularly, the rod simply rotates around the other. As the balls are small and the rod is "light", we can consider that there is negligible moment of inertia that would have to be overcome, so no forces are involved.
In reality this is a simplified model, but it's useful. If you start applying forces to the rod at other locations though (like in the middle), then this doesn't work and the rod must apply forces to the balls in other directions.