You are correct in your observation that the currently available Apple Magic Keyboards for iPad are compatible with the 13" and 11" models of iPad Pro. Due to differences in positioning of the attachment magnets and the Smart Connector, these are not compatible with the earlier 12.9" models of iPad Pro.
Apple's own Stores, both physical and online, generally only carry accessories for current and immediately preceding device models. While Apple Stores themselves won't be a viable source, other Apple retailers may still have accessories (including compatible keyboards) for your iPad Pro M2 - but only while stocks last. Once stocks are exhausted, that's it, they're gone.
Next you might look for third-party alternatives - however, you are again very likely to be searching for old stock amongst retailers. Again, third-party manufacturers soon discontinue model-specific accessories as demand inevitably dwindles over time as newer devices are released.
Logitech still market their Combo Touch for iPad Pro for the fifth and sixth generation iPad Pro 12.9":
https://www.logitech.com/en-gb/shop/p/combo-touch-ipad-pro.920-010214
Beyond these and searching though eBay and similar online sites, another option for your older model iPad Pro 12.9" might be to consider a simple folio-case for the iPad - and pair this with a good portable bluetooth keyboard.
Again, Logitech offer a potential candidate for the keyboard - with their Keys-To-Go 2 for iPad:
https://www.logitech.com/en-gb/shop/p/keys-to-go2-apple.920-013016
Folio cases for older model iPad are much more easily found. As for the bluetooth keyboard, there are many available.