tl;dr: despite having to drain its batteries to run its electronics heaters, it might survive a short eclipse, but since the mission can easily designed to be eclipse free it's simply good practice to do so.
Why risk it?
For more on this see @DavidHammen's answer.
The spacecraft has no internal "Goldilocks zone" where the electronics would naturally be at a comfortable temperature
From this answer to How can electronics on board JWST survive the low operating temperature while it's difficult to survive lunar nights? we can see that one side of the heat shield is "too hot" and the other side is "too cold" and in order to provide an electronics box inside of which the temperature is "just right" there is a complicated heat management system that depends upon the spacecraft being in its normal thermal state.
From Status of the JWST Sunshield and Spacecraft found in @Antzi
Most of the electronics is on the "hot side" but there needs to be some conventional electronics on the cold side (beside the cooled IR sensor chips).
Small thermal environments on the cold side are equipped with heaters to provide mini-environments at normal operating temperature for these electronic devices.
[...]Thermostatically control heaters are used to
maintain equipment above minimum required temperature while under cold conditions. Heater drive electronics (HDE) controlled heaters are used to maintain the +J3 panel, propulsion lines, battery, star tracker, and 1 Hz isolators within the required stability range.
The spacecraft component temperatures are maintained within the required limits by the use of radiators, heat pipes, MLI, and heaters. Thermostat and software controlled heaters are the two types used on this spacecraft. The software control heaters are used to maintain tight temperature control for critical spacecraft components and structures. The heaters are controlled by flight software with temperature feedback control. The flight software enables the ground to modify any TCS mission constants which include on/off heater set-points and failure thresholds.
The electrical heaters will generally run off of solar power.
Once you are in eclipse, the only way to keep the spacecraft alive, awake and communicating with earth is by draining the batteries to run heaters. And of course the faster you drain the batteries, the less time you can run the electronics on the same batteries.
The longer the eclipse, the bigger and heavier the batteries need to be to provide a margin of safety.
The more times you eclipse and cycle the batteries, tradeoffs between battery resiliency, power density and mass kick in.
It might survive a short eclipse, but since the mission can easily designed to be eclipse free it's simply good practice to do so.