How can I return an image from a custom REST API endpoint?

echo in the rest-api and not valid! You should using return to make output to Rest API.

For example:

function prefix_generate_cover_photo( WP_REST_Request $request ) {
    // Get method params
    $params = $request->get_params();

    // Data
    $data = array(
        'url'   => 'The image url',
        'title' => 'The image title',
    );

    // Create the response object
    $response = new WP_REST_Response( array( 'image' => $data ) );

    // Add a custom header (Optional)
    //$response->header( 'Cache-Control', 'no-cache' );

    return $response;
}