redirect any category in URL to the ID and post-name only – hundreds of pages affected

I’d suggest you to forget about htaccess in this case.

In your functions.php file add:

add_action( 'template_redirect', 'check_missing_urls' );
function check_missing_urls() {
    if ( ! is_404() ) {
       return;
    }
    $has_match = preg_match( '/\/?(\d+)/', $_SERVER['REQUEST_URI'], $match );
    if ( ! $has_match ) {
       return;
    }
    $new_url = get_permalink( $match[1] );
    if ( ! $new_url ) {
       return;
    }
    wp_redirect( $new_url, 301 );
    wp_die();
}

Please note that this is an untested code, use it as a very basic and rough idea to accomplish what you need.

Also, i’d suggest you to use 302 instead of 301, during the test period.