How to add an endpoint to WP

You need to return a WP_REST_Response object instead of an array.

See https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/ and https://developer.wordpress.org/reference/classes/wp_rest_response/.

error code: 523