Some clarification is needed.
The error can’t be reproduced with the categories specified above. I had a complex category tree with 2 “Apple” subcategories with different parent IDs.
Example (ID-Category):
1-Hardware > 3-Apple
2-Software > 4-Apple
When trying to add already existing subcategory “Apple” under “Software” category ID under “Hardware” is returned (i.e. first matching subcategory with name “Apple”)
$req = new WP_REST_Request( 'POST', '/wp/v2/categories' );
$req->set_param( 'parent', 2 );
$req->set_param( 'name', 'Apple' );
$r = rest_do_request( $req );
// returns $r->data['data']==3