Why wasn't the 737 MAX's landing gear lengthened enough to mount the engines under the wings, rather than in front of them?
The main gear sits between the wings and retracts inwards, such that the wheels will rest in the lower fuselage. Lengthening the main gear would either require to shift the gear attachment points outward or to retract one leg a bit forward and the other a bit backwards, such that both wheels will sit behind each other instead of side-by-side, as they do now - see below (source).



Shifting the gear attachment points out is clearly feasible but results in a major wing redesign. That would cost money so Boeing management decided that a software fix would be the better solution.

Placing the wheels in tandem would equally be a major and costly modification. A lot of systems would need to be relocated and all modifications would require testing. Boeing management cleary did not want to pursue this option.

Another quick fix is shortening the gear upon retraction. Decompressing the oleo strut in order to shorten the gear upon retraction is already standard in many fighter jets. Another solution is to add another hinge such that the gear leg will fold inside the gear bay. Such a solution was used on the Grumman F-8F Bearcat and is pictured below (source).



From what I understand, this particular solution was applied to the longest 737 version to allow enough tail clearance for rotation, but added weight and complexity. Of course it could be applied to the rest of the 737 MAX fleet as well, but again Boeing management tried to save money and weight by implementing a software-only solution.

But the engine location would be fine if a larger horizontal tail would be added, increasing stability at high angle of attack and making a quick software fix unnecessary. Again, this would add cost and weight and make the aircraft less competitive.