How to set subcategory in Woocommerce?

You will have to first insert the term as required using wp_insert_term.

wp_set_object_terms( $post_id, 'Lense', 'product_cat', false); 

This function checks if ‘Lense’ term exist in product_cat or not. If does not exist, then create and assign.
Check whether term already exists or not

$id = term_exists( 'canon','product_cat',$parent_id ) //$parent_id is parent term id, in your case id of Lense
if($id == NULL)
{
    $id = wp_insert_term(
      'Canon', // the term 
      'product_cat', // the taxonomy
      array(
        'description'=> 'Test description',
        'slug' => 'canon',
        'parent'=> $parent_term['term_id']  // get numeric term id of parent - Lense
      )
    
    );
}

wp_set_object_terms( $post_id,$id, 'product_cat',true); 

This will work.

// No space is allowed in taxonomy name