Specify number of posts for sub-category page

OK, how about this then? (Changed from first try – now tested.)

function my_post_queries( $query ) {

    if ( ! is_admin() && $query->is_main_query() ) {

        if ( is_category( 7 ) ) {

            $query->set( 'posts_per_page', 6 );

        }

        //works with pretty permalinks
        $cat_id = get_queried_object()->term_id;

        if ( cat_is_ancestor_of( 7, $cat_id ) ) {

            $query->set( 'posts_per_page', 12 );

        }

    }

}

Note: Still not sure about the purpose or effect of including return ;‘s. Had no obvious effect on functionality, so have left them out.