How to pass all received IDs through the function for in_category

You can’t pass arrays by passing a string with commas into array(), that’s not how arrays work in PHP. Your code is the equivalent of:

if ( in_category( array( '1,2,3,4' ) ) ) {
}

Which is checking for a single category with the ID '1,2,3,4', which can’t exist.

For what you want to do, your function needs to return an array of IDs, which will be passed directly into in_category(), without array():

function get_cats(){
  $id       = 1;
  $tax      = 'category';
  $children = get_term_children( $id, $tax );
  $cats     = array(); // Prepare an array to return.

  foreach ( $children as $child ) {
    $term   = get_term_by( 'id', $child, $tax );
    $cats[] = $term->term_id; // Add ID to the array:
  }

  return $cats; // Return the array.
}

Then:

if ( in_category( get_cats() ) ) {
  //
}

However, it needs to be pointed out that your get_cats() function is extremely redundant. You’re using get_term_children() to get the IDs of the children, but then for some reason you’re looping through those IDs to get the full term, just so you can get the ID. This doesn’t make sense, because you already had the IDs.

So really, you don’t need the get_cats() function at all. Just use get_term_children():

$term_ids = get_term_children( 1, 'category' );

if ( in_category( $term_ids ) ) {

}