Get node in custom token to be used in Pathauto url alias pattern
You get the node from $data:

  if (!empty($data['node'])) {
    /* @var \Drupal\node\NodeInterface $node */
    $node = $data['node'];
  }


It is the responsibility of the code which calls replace() to provide the correct context (in case of Pathauto the node for which it's building the alias).