WordPress showing fatal error on wp_set_object_terms line

wp_insert_term returns an array on success or a WP_Error in case of problems.

You should catch the error and look for the reason why it fails.

One problem could be, how you create the slug, because it could lead to an error during the creation of the term. Just use $slug = sanitize_title( $T_product_type ) or – even better – let the function wp_insert_term create a unique slug for you.

Another thing is the name itself. Based on what I wrote before I would propose to change your code like this:

function set_product_category_woo( $T_product_type, $post_id ) {
    $name = trim( stripslashes( $T_product_type ) );
    if ( empty( $name ) ) {
        return;
    }

    $product_categories = term_exists( $name, 'product_cat' );
    if ( empty( $product_categories ) ) {
        $resp = wp_insert_term( $name, 'product_cat' );

        if ( ! is_wp_error( $resp ) ) {
            wp_set_object_terms( $post_id, $resp['term_id'], 'product_cat' );
        }

        // rest of your code