Index: src/wp-includes/rest-api.php
===================================================================
--- src/wp-includes/rest-api.php	(revision 43859)
+++ src/wp-includes/rest-api.php	(working copy)
@@ -18,6 +18,8 @@
  * Registers a REST API route.
  *
  * @since 4.4.0
+ * @since 5.1.0 Enforce requirement to use on the rest_api_init hook.
+ *
  *
  * @param string $namespace The first URL segment after core prefix. Should be unique to your package/plugin.
  * @param string $route     The base URL for route you are adding.
@@ -28,7 +30,10 @@
  * @return bool True on success, false on error.
  */
 function register_rest_route( $namespace, $route, $args = array(), $override = false ) {
-	if ( empty( $namespace ) ) {
+	if ( ! doing_action( 'rest_api_init' ) ) {
+		_doing_it_wrong( 'register_rest_route', __( 'REST API routes must be registered on the rest_api_init action.'), '5.1.0' );
+		return false;
+	} else if ( empty( $namespace ) ) {
 		/*
 		 * Non-namespaced routes are not allowed, with the exception of the main
 		 * and namespace indexes. If you really need to register a
