From Wikipedia:
Placing engines on the wing provides beneficial wing bending relief in
flight. The further the engines are away from the fuselage the greater
the wing bending relief so engines buried in the wing root provide
little relief. Almost all modern large jet airplanes use engines in
pods located a significant distance from the wing root for substantial
wing bending relief.
One could imagine that, in flight, the wings are holding up the aircraft, but this causes a massive bending moment at the wing roots (just visualize an airplane suspended by ropes from the wings). As such, is favourable to have the airplane body be as light as possible, and put as much mass (e.g., fuel) as possible on the wings, where the lift forces coincide (or at least, are closer to) the weight of the engine, reducing bending moment on the wing roots. This allows for smaller (and thus more aerodynamically efficient) wing structures.
As noted in the comments, placing the engines further away of course increases downwards bending moment when the plane has landed. However, this will be 1g by definition (at touchdown, the wings still provide lift (generally)), whereas during the flight, an airplane is designed to take up to 2.5g (and, I suppose not completely coincidentally, -1g).