How to show WordPress parent and child category using a different template?

You can do this couple of ways.

  1. By checking depth of the category/sub-category. If we are browsing main/parent categories then show a custom template, if we are on sub-categories then show another template and this goes on.
  2. We can check if a category is ending category of not. Ending category means if a category does not have any child then it should show default category.php template.

Which method you should use is depends on your project requirements. Here I am going to explain first one because it’s very flexible and I think will suit your purpose.

WordPress have template_include function that executes immediately before WordPress includes the predetermined template file. This can be used to override WordPress’s default template behavior.

function wpse_template_check( $template ) {
    if ( is_category() ) {
        // Get category information
        $cat = get_query_var( 'cat' );
        $cats_str = get_category_parents( $cat, false, '%#%' );
        $cats_array = explode('%#%', $cats_str);
        $cat_depth = sizeof( $cats_array )-2;

        // Check category depth
        $new_template = locate_template( array( 'category-custom-template.php' ) );
        if ( $cat_depth == 0 && '' != $new_template ) {
            return $new_template;
        }
    }
    return $template;
}
add_filter( 'template_include', 'wpse_template_check' );

This function calculates category depth and checks if current category is main/parent categories. If it’s true and category template exists then it will replace category template to category-custom-template.php.

I have tested it and it’s working but you should note that it’s based on category depth so all parent categories will have same custom template.

Although you can customize this function to do more and as fit your requirements.