Most military strategists understood before the war broke out how important recent tech developments (e.g. machine guns, improved artillery, etc) were in the defense. Prior to the outbreak of hostilities, most military thinkers felt that it was best to bypass defensive fortifications. They understood that charging trenches and machine guns would lead to horrendous casualties. They wanted to fight a war of maneuver to counter strong static defenses. This was essentially a no-brainer.
What they did not foresee was 1) how rapidly ad-hoc fortifications (i.e. trench lines) could be extended; and 2) the massive amount of ammunition expenditure by artillery. That part is critical... because it means that advances had to slow down to account for the logistics train. Which meant that fortifications couldn't be as easily bypassed... which meant trenches could be extended further...
And thus, quite rapidly, the entire western front was covered in trenches/fortifications. At that point, it all becomes political. The governments want a win. At any cost. And orders are orders. When you can't go around, there's not much you can do but charge forward (after an huge artillery barrage, of course... which leads to more logistical headaches)
In short, the military leadership in ww1 wasn't any more "stupid" than usual. They were simply stuck between a rock and hard place.