When you flip the switch from green (on) to gray (off), the keyboard should immediately disconnect from Bluetooth and stop responding. However, if yours remains active even after toggling the switch, a few things could be going on.
Here are a few things you can check/try:
- Try fully charging your keyboard and then flipping the switch again. If that doesn’t work, try resetting the keyboard by turning it off, waiting 30 seconds, and then turning it back on while holding the power switch in the "on" position for a few seconds.
- Even if the switch isn’t working, you can force a disconnect from macOS by going to System Settings → Bluetooth, finding your Magic Keyboard, and clicking Disconnect.
- It may be possible that your Mac might still recognize the keyboard as connected because of a macOS bug. Although I am not aware of any at this time, restarting Bluetooth (turn it off and on in System Settings → Bluetooth) might help.
If none of above helps, the power switch itself may be faulty. Should that be the case, the standard Apple one-year warranty covers manufacturing defects. If past that time, but you purchased an AppleCare+ plan with your Mac Studio/Magic Keyboard, that extends that warranty for several years. Either way, you would need to take the keyboard to your local Apple Store or Apple Authorized Service Provider to have them take a look and provide you with your options.