Related Posts: Notice: Undefined offset: 0

When you use wp_list_pluck on $terms what you get is an array where the key is the same as the value. If you dump the contents of $term_ids you’ll see something like:

array(
    [42] => 42,
    [56] => 56
}

The code in query.php tries to reference the zero index of the term_ids array, but there is no index 0, hence the warning.