We investigate the chemical history of interstellar OCS and SO2 by deriving a statistically-significant sample of gas-phase column densities towards massive protostars and comparing to observations of gas and ices towards other sources spanning from dark clouds to comets. We analyze a subset of 26 line-rich massive protostars observed by ALMA as part of the ALMAGAL survey. Column densities are derived for OCS and SO2 from their rare isotopologues O13CS and 34SO2 towards the compact gas around the hot core. We find that gas-phase column density ratios of OCS and SO2 with respect to methanol remain fairly constant as a function of luminosity between low- and high-mass sources, despite their very different physical conditions. The derived gaseous OCS and SO2 abundances relative to CH3OH are overall similar to protostellar ice values, with a significantly larger scatter for SO2 than for OCS. Cometary and dark-cloud ice values agree well with protostellar gas-phase ratios for OCS, whereas higher abundances of SO2 are generally seen in comets compared to the other sources. Gaseous SO2/OCS ratios are consistent with ices toward dark clouds, protostars, and comets, albeit with some scatter. The constant gas-phase column density ratios throughout low and high-mass sources indicate an early stage formation before intense environmental differentiation begins. Icy protostellar values are similar to the gas phase medians, compatible with an icy origin of these species followed by thermal sublimation. The larger spread in SO2 compared to OCS ratios w.r.t. CH3OH is likely due to a more water-rich chemical environment associated with the former, as opposed to a CO-rich origin of the latter. Post-sublimation gas-phase processing of SO2 can also contribute to the large spread. Comparisons to ices in dark clouds and comets point to a significant inheritance of OCS from earlier to later evolutionary stages.