Thanks to Milo who asked an important question: Where is this code?
I put it below where ive have registered the taxonomy and then it worked:
function register_taxonomy() {
$labels = array(...);
$args = array(...);
register_taxonomy( 'ncategory', null, $args );
$parent_term = term_exists( 'Gender', 'ncategory' ); // array is returned if taxonomy is given
$parent_term_id = $parent_term['term_id']; // get numeric term id
//echo $parent_term_id;
$ret = wp_insert_term(
'Male',
'ncategory',
array(
'description'=> '',
'slug' => '',
'parent'=> $parent_term_id
)
);
echo is_wp_error($ret);
}