Your Magic Keyboard has no internal battery - and therefore will come to no harm if left connected to its Power Adapter.
However, at its heart, the Power Adapter is a switched-mode power supply. Without delving into detail of how these work, suffice to say that leaving them connected to AC Mains for extended periods, without a load, is not recommended. Aside from other issues, doing so can dramatically shorten the life of the electronics.
Leaving the Power Adapter connected without load also consumes unnecessary power - which, from a “green” perspective is not environmentally friendly. Similarly, as with all AC Mains powered devices, leaving the Power Adapter connected to AC Power when not being actively used presents a small but avoidable safety/fire risk.
If you wish to extend the lifespan of your power (charging) electronics, you would be well advised to switch-off when unused.