How to update the children of a post?

get_children returns an array of post objects by default:

https://developer.wordpress.org/reference/functions/get_children/

So you would have to use 'ID' => $child->ID, in this case… also my want to wrap the foreach with if (count($children) > 0) {} to prevent possible errors where there are no children. ie:

$children = get_children( $mainid );

if (count($children) > 0) {
    foreach ($children as $child){
        wp_update_post(
            array(
                'ID' => $child->ID, 
                'post_status'   =>   'wartend',
                'post_parent' => $mainid
                )
            );
        }
    }
}