We report on the composition of comet C/2023 H2 (Lemmon) (hereafter C/2023 H2) as measured with CRIRES$^+$ at VLT/ESO, under the Director Discretionary Time program: 2112.C-5015. We observed C/2023 H2 between November 24 and 27, 2023, after perihelion and during its close approach to Earth. We used three settings sampling the spectral region from approx 2.5 to 5 mu m, to search for fluorescence emission lines of H$_2$O, HCN, C$_2$H$_2$, NH$_3$, C$_2$H$_6$, H$_2$CO, CH$_3$OH, CH$_4$, and CO. C/2023 H2 spectra are dominated by signatures from hyper-volatile species, namely CO, C$_2$H$_6$, and CH$_4$, while it is particularly difficult to identify lines from less volatile species such as water or methanol. When compared to other comets, C/2023 H2 has an overall typical-to-enriched composition, with CO showing one of the highest infrared values reported so far in Solar System comets within 2 au from the Sun. In this respect, C/2023 H2 shares many similarities with C/2013 R1 (Lovejoy), C/2009 P1 (Garrad), and C/1999 T1 (McNaught-Hartley), although still being rather unique. Results from the analysis of optical spectra (approx 300 to 650 nm) obtained on November 16, 2023, using the Intermediate Dispersion Spectrograph at the Isaac Newton Telescopes are consistent with the infrared ones. Assuming that the composition of C/2023 H2 is original, this comet most likely formed in a region of the disc where CO was particularly enriched, or it could have been captured from other planetary systems forming in the Sun's birth cluster. Similarities with a few other comets suggest the existence of a sub-class of CO-enriched comets, which may be currently under-sampled. Alternatively, water sublimation may have been ineffective due to the presence of a thick dust mantle covering the nucleus surface.