Found the solution. By default wordpress doesn’t show hierarchical URL for custom taxonomies.
Therefore while registering custom taxonomy, we must include the rewrite variable.
$args = array(
'rewrite' => array( 'hierarchical' => true ),
);