Iterate over get_post_meta() result

You’re clobbering the value in the $users array with every iteration of the foreach loop. To add a new item to an array, you should use $users[] = {...}, not $users = {...}.

function get_preselect_values()
{
    $volunteers = get_post_meta($_POST['element_id'], "volunteers", false);
    $users = array();
    
    foreach ($volunteers as $volunteer) {
        foreach ($volunteer as $volun) {
            $users[] = $volun['ID'];
        }
    }
    echo json_encode($users);
    die;
}

add_action('wp_ajax_get_preselect_values', 'get_preselect_values');
add_action('wp_ajax_nopriv_get_preselect_values', 'get_preselect_values');