Add Catgory (assign) to Post Programmatically (without editing)

You can set post terms programmatically with wp_set_object_terms(). There’s also wp_set_post_terms() which is a wrapper for the first function, but with some extra processing of the parameters in it.

foreach ( $array_of_post_ids as $post_id ) {
    // appends my-category to a post's categories
    wp_set_object_terms( $post_id, 'my-category', 'category', true );
}