Hi,
The HP support site lists drivers for very old Mac operating system versions only.
This would be experimental, but you could perhaps try the HP 5.1.1 Printer Software Update. According to the system requirements, macOS 12 Monterey and newer would not be compatible, but you may possibly want to test it anyway. It may not work at all. There is an HP Color LaserJet CP1510 Series version 19.13 driver listed in the article Printer and scanner drivers for Mac - Apple Support.
However, it is difficult to understand why it works with the M1 machine but not with the M2. What kind of drivers/settings were used on the M1? How is the printer connected?
The HP Color LaserJet CP1518ni appears to support PCL 6 and HP postscript level 3 emulation, so if nothing else works you could perhaps try generic PCL or postscript printer software (see also the Use option under the Add a network printer by specifying its IP address section in Add a printer to your printer list so you can use it on Mac – Apple Support (UK)).
As always, make sure that you have backup copies of all important files before testing anything. Software conflicts cannot be ruled out. You may have to reset the printing system (link below) between tests.
Reset the printing system on your Mac to solve a problem – Apple Support (UK)