Custom route and query

There are 3 issues with your code:

  1. The proper syntax of registering your custom REST API route, is as follows:

    register_rest_route( $namespace, $base_URL, $args, $override );
    

    So:

    register_rest_route( 'boss/v1', '/latest-quiz-results', array(
        'methods'  => 'GET',
        'callback' => 'get_latest_quiz_results'
    ) );
    

    Consult the reference for more information.

  2. In the get_latest_quiz_results(), $wpdb is not defined because you’re missing global $wpdb; at the top:

    function get_latest_quiz_results() {
        global $wpdb; // Add this.
        ...
    
        return $results;
    }
    
  3. Also in get_latest_quiz_results(), you incorrectly called wpdb::prepare() — the second parameter is mandatory, and there needs to be at least one placeholder (e.g. %s). So for example:

    $query = $wpdb->prepare( "SELECT ... WHERE 5PxenC_learndash_user_activity_meta.activity_meta_key = %s", 'pass' );