Apple - Can you pair macOS and iOS device with same Magic Keyboard and switch between them?
No - Apple's firmware on the keyboard remembers the last paired device.
Some bluetooth keyboards can switch back and forth, but that feature isn't available on Apple's current hardware.
This works for me. I have an iMac (late 2013) and an iPad Air 2. I have set up my Magic Keyboard to be recognized by both devices. You can force pair a 2nd connection by holding down the power button on the Keyboard (maybe you are missing this step). You don't want either device to "forget" the keyboard. Once you've done that, you can then disconnect the keyboard from the iMac (in your case Macbook) using the bluetooth drop down in the finder menu bar, then connect to the ipad using the Bluetooth settings on the ipad. When you want to switch back again, first disconnect (don't choose forget) on the ipad bluetooth settings (using the (i) in a circle) then go back to the bluetooth menu/Keyboard option on the iMac finder menu and choose connect. I don't have to turn off bluetooth completely on either computer.
You can remove pairing from the Mac when you hold Shift-option and click the bluetooth symbol on the menu bar. Bluetooth should be on. It then offers the possibility to remove it, whereupon it becomes disoverable again to the iPad.