The 4.62$mu$m (2164.5 cm$^{-1}$) `XCN band has been detected in the $M$-band spectra of 34 deeply embedded young stellar objects (YSOs), observed with high signal-to-noise and high spectral resolution with the VLT-ISAAC spectrometer, providing the first opportunity to study the solid OCN$^-$ abundance toward a large number of low-mass YSOs. It is shown unequivocally that at least two components, centred at 2165.7 cm$^{-1}$ (FWHM = 26 cm$^{-1}$) and 2175.4 cm$^{-1}$ (FWHM = 15 cm$^{-1}$), underlie the XCN band. Only the 2165.7-component can be ascribed to OCN$^-$, embedded in a strongly hydrogen-bonding, and possibly thermally annealed, ice environment based on laboratory OCN$^-$ spectra. In order to correct for the contribution of the 2175.4-component to the XCN band, a phenomenological decomposition into the 2165.7- and the 2175.4-components is used to fit the full band profile and derive the OCN$^-$ abundance for each line-of-sight. The same analysis is performed for 5 high-mass YSOs taken from the ISO-SWS data archive. Inferred OCN$^-$ abundances are $leq$ 0.85 % toward low-mass YSOs and $leq$ 1 % toward high-mass YSOs, except for W33 A. Abundances are found to vary by at least a factor of 10--20 and large source-to-source abundance variations are observed within the same star-forming cloud complex on scales down to 400 AU, indicating that the OCN$^-$ formation mechanism is sensitive to local conditions. The inferred abundances allow quantitatively for photochemical formation of OCN$^-$, but the large abundance variations are not easily explained in this scenario unless local radiation sources or special geometries are invoked. Surface chemistry should therefore be considered as an alternative formation mechanism.