How safe is it to use Apple's wireless keyboard?
It’s actually quite safe to use Bluetooth keyboards.
Since 2009 on, bluetooth keyboards have encrypted all traffic end to end with the exception of service discovery.  In other words, only the advertising packets that basically say “I’m a keyboard” or “I’m a trackpad or mouse” are unencrypted.  Everything else, including the authentication is encrypted.
How does macOS Sierra securely pair with Bluetooth keyboards without a code?
Entering a key or a passcode is not part of the security mechanism; its a form of Simple Secure Pairing or SSP.  The passkey is just a way to identify devices to be paired.  It’s definitely not a way to prevent MITM attacks.
So, is Bluetooth safe?
It’s more accurate to say “it’s safe enough for US Government standards.

Bluetooth adheres to U.S. federal security regulations, ensuring that all Bluetooth devices are capable of meeting and exceeding strict government security standards.

NIST Compliant: The National Institute of Technology develops security standards and guidelines for federal agencies to protect their information and information systems.

FIPS Approved: These Federal Information Processing Standards are developed by NIST in accordance with the Federal Information Security Management ACT (FISMA).



Further reading:
NIST Special Publication 800-121 Revision 2N Guide to Bluetooth Security