I noticed it too. My assumption was osascript fails gracefully when using ssh, whereas xdpyinfo will print an error to stderr.

Could also change it to:

elif is_ubuntu; then
    focus_window_id=$(xdpyinfo 2>/dev/null | grep -Eo 'window 0x[^,]+' |\
                                    awk '{print $2 }')

and just let it return an empty string (note: there's an exact same check later on)
then [[ $focus_window_id == $terminal_window_id ]] will return true and notify won't be called