As others have pointed out, defense vs. offense is largely a product of the technology of the time. The most stark example is WWI, where weapons technology greatly overpowered transportation technology. Why was trench warfare a thing? Because both sides had machine guns, artillery, and no way to circumvent the aforementioned machine guns and artillery. Remember, the Central Powers never surrendered. They just asked for peace first, because they were running out of shells and bullets faster than the Entente was running out of men to throw into the meat grinder.
Contrast that with WWII, when digging in did little to no good, largely due to advances in air power and armor, as Putin already mentioned. The Entente didn't have Sherman tanks, airborne divisions, and specialized ground attack aircraft in WWI, but they sure as hell did in WWII.
In a "low-intensity" conflict like Korea or Vietnam, you usually see a mix of offense and defense. Korea was one big running battle for over a year before the lines stabilized and it turned into a trench war. The trench war in Korea wasn't a product of too much power and not enough mobility; it was a problem of no political will on either side. Both China and the United States had more than enough resources to finish the fight one way or the other, but that was a risky idea from a political standpoint.
Same thing in Vietnam, although the type of fighting was dependent on terrain AND political capital. Khe Sanh and the other mountainous battles were largely trench battles for the Americans, whereas urban battles like Hue and patrolling in the jungle were running affairs. The United States had more than enough military power to completely conquer North Vietnam with conventional forces (which would have been a highly mobile campaign; there are few forces on Earth capable of stopping a sufficiently motivated column of M48 Patton main battle tanks), but no political will to do so.