If you use macOS Ventura or later, go to Settings → Keyboard and you’ll see a toggle for automatic backlight. You can also adjust brightness with Fn + Touch Bar or Control Center. On older macOS versions it’s in Keyboard prefs. Auto-adjust depends on the ambient light sensor, which can be fooled if you cover the top bezel.