The reason a gasoline engine will run hot and potentially melt pistons when run "lean" is that a diesel engine generally operators under a different portion of the "lean" spectrum. As shown below, peak flame temperature is achieved at the ideal air/fuel ratio (stoichiometric ratio), with the flame temperature being lower at both richer and leaner conditions.
View attachment 826104
In a gasoline engine, the goal mixture for maximum power is actually slightly rich. Visually this means the engine is operating somewhere on the sloped line between 0.5 and 1.0 in the above image. Adding air to the original "goal" mixture moves the air/fuel ratio closer to 1.0, which increases the flame temperature. This new condition is leaner than the original "goal" but is not actually "lean" in the absolute sense. If you continued to add air past the stoichiometric ratio the flame temperature would come back down and the engine would run cooler again on the right side of the peak.
This article from Summit Racing shows some common ratios for cruise, idle, and Wide-Open-Throttle relative to the stoichiometric ratio:
Summit Racing - Air/Fuel Mixtures
Diesel engines operate on the opposite side of the curve: At idle they are way past 2.0 on the right side of the peak flame temperature with a very high air/fuel ratio. As more fuel is added, the air/fuel ratio gets richer and richer, moving the ratio closer to 2.0 and eventually 1.0 where the peak flame temperature occurs.
To summarize, they respond to becoming more rich or more lean differently because they operate on different sides of the peak flame temperature. WHY gasoline engines run slightly rich instead of designing the engine to handle the peak flame temperature is another topic, and likely has to do with engineering/control of the process, cost, emissions, and/or all of the above.