How to make all post in to a category?

First query all post

$args = array(
    'post_type'         =>'posts',
    'post_status'       =>'publish',
    'posts_per_page'    =>-1

);
$query = new WP_Query($args);
$post_ids = array();
if($query->have_posts()){
    while ($query->have_posts()){
        global $post;
        $query->the_post();
        array_push($post_ids,$post->ID);
    }
}

Now you have an array called $post_ids which contains all post’s id .

Now , change the categories

Loop through the array and change the categories

$post_categories= array('Past Posts');
foreach ($post_ids as $key => $post_ID) {
    if(!in_category('Past Posts')){
        wp_set_post_categories( $post_ID, $post_categories, true );
    }
}

If you want to append a category then set the third parameter of wp_set_post_categories of this function true or if you want to replace then make it false .

Put this code in functions.php , you can delete this code after your work is done