How to display related posts from parent category

Just change this one line:

   $cat_obj = $wp_query->get_queried_object();
    $thiscat_id = $cat_obj->term_id;
    $thiscat = get_category($thiscat_id);
    $chi = array();
    if (!empty($thiscat->parent)) {
        $parentcat = get_category($thiscat->parent);
        $categories_chi=get_categories(
            array( 'parent' => $parentcat->cat_ID )
        );

        foreach ($categories_chi as $key => $value) {
            $chi[] = $value->cat_ID;
        }
        $pare = array($parentcat->term_id);
        $ids = array_merge($pare, $chi);
    } else {
        $ids = array($cat_obj->term_id);
    }

    $related  = get_posts(array( 'category__in' => $ids, 'numberposts' => 10));