Yes, the Bluetooth Magic Keyboard for Mac can be used with any model of iPad - however, the keyboard can only be paired with one device at a time. Unlike some third-party Bluetooth keyboards, the Bluetooth Keyboard for Mac doesn’t support pairing to multiple devices.
If already paired with your Mac, you will need to use the pairing process with the iPad before you’ll be able to use the keyboard. Similarly, once paired with the iPad, you’ll need to re-pair with the Mac before being able to use the keyboard again with the Mac.
Third-party Bluetooth Keyboards that support pairing with multiple devices can be simply and instantly switched between devices by pressing a single key on the associated keyboard.