Index: src/wp-includes/rest-api.php
===================================================================
--- src/wp-includes/rest-api.php	(revision 44558)
+++ src/wp-includes/rest-api.php	(working copy)
@@ -17,7 +17,10 @@
 /**
  * Registers a REST API route.
  *
+ * Note: Do not use before the {@see 'rest_api_init'} hook.
+ *
  * @since 4.4.0
+ * @since 5.1.0 Added a _doing_it_wrong() notice when not called on or after 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.
@@ -41,6 +44,10 @@
 		return false;
 	}
 
+	if ( ! did_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' );
+	}
+
 	if ( isset( $args['args'] ) ) {
 		$common_args = $args['args'];
 		unset( $args['args'] );
Index: tests/phpunit/tests/rest-api.php
===================================================================
--- tests/phpunit/tests/rest-api.php	(revision 44558)
+++ tests/phpunit/tests/rest-api.php	(working copy)
@@ -14,9 +14,11 @@
  */
 class Tests_REST_API extends WP_UnitTestCase {
 	public function setUp() {
+		parent::setUp();
+
 		// Override the normal server with our spying server.
 		$GLOBALS['wp_rest_server'] = new Spy_REST_Server();
-		parent::setUp();
+		do_action( 'rest_api_init' );
 	}
 
 	public function tearDown() {
