Gain is the ratio of the output voltage of a component to its input voltage. In the case of a preamp or a line stage or other component having a volume control it is usually defined based on the volume control being set to its maximum position. It can be defined either as a numerical ratio (e.g., 100 times), or in db (db = 20 x logarithm(Vout/Vin); 100x = 40 db).
Usually a CD player or DAC or other digitally-based source component will provide higher output voltages than most phono stage/cartridge combinations, and so the resulting volumes will be different unless the line stage provides independently adjustable level settings for each input.
A factor that can dramatically affect perceived loudness is the dynamic range of the recording, and consequently how much dynamic compression it has been subjected to when it was engineered. Our hearing mechanisms tend to sense volume based on the average level of what is heard, rather than on brief dynamic peaks in volume or on passages that are significantly lower in volume than the average. So if everything else is equal (including the volume control setting) if a recording that has been compressed to a narrow dynamic range (i.e., so that a relatively small difference in volume occurs between the loudest notes and the softest notes) it will tend to sound louder than if the same music has been engineered with minimal or no dynamic compression.
Also, of course, recordings can differ somewhat in the overall volume levels they have been mastered at, even if the music and the amount of dynamic compression are similar.
Regarding phono stage gain, depending on the particular phono stage and cartridge, as well as on the gains and sensitivities of the downstream components including the speakers, there will usually be a relatively small range of phono stage gains that will result in an optimal balance of sonics, noise levels, volume control positions, and avoidance of any possibility of overloading either the phono stage or the preamp. Too much gain or too little gain can adversely affect some combination of these factors.
Regards,
-- Al