WP-CLI runs most wp db * commands right after wp-config.php is located, but before the rest of WordPress is loaded: https://github.com/wp-cli/wp-cli/blob/d9d405a4ca01ba23e80277b8cb9000857e84e0cd/php/WP_CLI/Runner.php#L875
This is a special case system that should be switched to using named WP-CLI hooks.
From #1 (comment)