Hi,
I think gain is very similar to ISO, just different ways to express how much the signal gets boosted (pre-amplified) before being recorded. ISO is "equivalent fim sensitivity" while gain is basically multiplication in decibels. Ideally you want your gain to be high enough for fixed pattern noise and other problems of your sensor to become negligible compared to the signal, and low enough to not start burning your highlights or introduce other nonlinearities.
I believe the rule of thumb
given an exposure time is to use the highest possible gain which
a) will not cause clipping to the right of your histogram
andb) keep the bulk of the data to the left 1/3rd of the histogram
Or something like that.
Exposure is the dominant parameter (I am assuming for the simplicity that the subject and conditions are the same, that f/number and aperture is constant so you can only change exposure and gain). Because exposure affects how much signal you are collecting, not how it gets amplified. You generally want to have the longest exposure possible and lower the gain. But if you can do only short exposures (say 15 seconds) because your tracking is less than optimal, because there is light pollution, because whatever, you want to bring the gain high enough to satisfy (a) and (b), otherwise you subs will show very high fixed pattern noise.
The situation becomes a little more complicated because for all sensors there is a value for gain above which there are no significant gains in terms of fixed pattern noise elimination while there are detrimental results in terms of colour detail. Otherwise everyone would be shooting at the maximum gain (or the maximum ISO) and we wouldn't need tracking or big telescopes at all

The reason you are seeing conflicting advise is because all factors (subject type, exposure, f/number, aperture, sky background levels, tracking, gain) affect each other and there is no single optimum value for everybody, even with the same sensor/camera. Planetary lucky imaging presents very different constraints from deep sky imaging, light polluted sites are different from dark sites, guided can expose longer than unguided and so on and so forth.
There is a very good analysis here:
https://clarkvision.com/articles/iso/it speaks in terms of DSLR cameras and ISO, but it's practically the same thing.
Cheers,
D.