The currently available Magic and Smart Folio keyboards for the sixth generation iPad Pro 12.9” are back-compatible with the 3rd to 6th generation iPads Pro 12.9”.
If purchased directly from Apple, you will always be sent the most recent version. Older version devices and accessories are generally only available from other Apple retailers; Apple Authorised Retailers will generally identify and differentiate earlier versions from current models.
The fifth and sixth generation iPad Pro 12.9” are physically identical - and differ only from the third and fourth generation iPads Pro in being slightly thicker to accommodate the newer XDR miniLED-backlit display.
The third and fourth generation iPad Pro 12.9” are similarly identical in physical dimensions with only one significant exception - namely the rear camera. The third-generation iPad Pro 12.9” has a single-lens camera - whereas the fourth generation iPad Pro 12.9 shares the same camera-array bump as the fifth and sixth generation.
The newer keyboards have a larger aperture to accommodate the camera array - this also supporting the single-lens of the third generation.
Should you need to do so, you can compare all the models here:
https://www.apple.com/ipad/compare/?modelList=ipad-pro-12-9-6th-gen,ipad-pro-12-9-5th-gen,ipad-pro-12-9-4th-gen
In summary, unless you go out of your way to find an older keyboard from an independent retailer, you need have no concern that an Apple Magic or Smart Folio Keyboard purchased directly from Apple will not be the current model accessory.