There are a few factors involved AFAIU:
- You don't want to be shooting through the Milky Way's own primary mass as nearby dust and gas will obstruct more distant objects.
- "Nearby" objects --- stars within the Milky Way, reasonably nearby galaxies --- might also tend to blow out the image. Though for the most part these end up being point sources. It's artefacts such as spikes which give the most obstruction.
In the case of the JWST, the fact that it's looking into the infrared means that it can see object which are literally invisible to Hubble regardless of how long the exposure.
The question of why space is black (or alternatively: why it's not uniformly light) is known as Olber's Paradox or "the dark-sky paradox", and dates back to the time of Keppler. Effectively: the universe has a finite age, and there is not an infinite number of stars (or other light sources) as one goes back in time.
https://starchild.gsfc.nasa.gov/docs/StarChild/questions/que...
https://en.wikipedia.org/wiki/Olbers%27_paradox
There is a uniform illumination of the Universe that can be detected, as microwave radiation, known as the cosmic backgroud radiation. That occurs well below JWST's sensor range (0.6–28.3 μm), however, with a peak wavelength of about 1 mm.
(a) The universe is infinite, but has been (and will always be) stretching faster than would allow light from galaxies too far away to ever reach us.
(b) The universe is infinite and not even stretching, but there is enough (dark?) matter in it to eventually block any ray of light coming from infinitely far away.
This is how these images of very dim, distant galaxies are created without foreground stars blowing out the whole image.
This image stacking technology has crept in to smartphone cameras in the last handful of years, most prominently as "night mode".
If you're interested in distant constant objects, then near-transient signals can be safely ignored and removed.
The wikipedia article has a lot of details, including masking the CR's, removing some scattered light from Earth, the use of multiple color bands, and super-resolution using slightly different pointing from frame to frame. All this processing is done at the single-image level, and motivates dividing up the exposure time into chunks.
The ~340 exposures were taken over about 10 days and spread over 4 color bands. The typical integration time for one exposure appears to have been about 30 minutes.
The goals are to maximise light capture (the objects being imaged are dim and distant), whilst miniising any degredation from other factors. JWST doesn't ahve to deal with skyglow, daylight, or satellite interference. It may still be seeing other solar system bodies (depending on where it's aiming), but mostly would be subject to cosmic-ray interference, probably impacting on the light sensor itself.
Since those are essnetially instantaneous and randomly distributed with time, by "stacking" images and filtering out transient events (taking an average or median brightness AFAIU).
I'm not sure to what extend HDR is used in astronomical imaging.
There is a lot of post-processing and palette selection to apply colours to what are just intensity maps at a given frequency.
https://astrobackyard.com/tutorials/stack-exposures/
https://www.skyatnightmagazine.com/astrophotography/astropho...