If you want to access Drupal entities, then you should use EntityTypeManager's getStorage() method to return a storage controller for nodes:
// Get a storage handler reference for Nodes.
$node_storage = \Drupal::entityTypeManager()->getStorage("node");
// Load an arbitrary node, as identified by the $nid variable.
$node = $node_storage->load($...
I think you are really going to struggle to get this to work using the default taxonomy term page view. However, you can disable the view and then use the default entity full content display for terms and do whatever you'd like for it (just like a node page).
Disable the taxonomy term display that controls /taxonomy/term/%tid. This will allow the term's ...
hook_pathauto_pattern_alter() is only invoked when:
The entity has a path field
Pathauto processing is enabled
For entities that support revisions, the entity is using the default revision
A default pattern has been set for that entity
$entity->toUrl()->getInternalPath() doesn't throw a EntityMalformedException, UndefinedLinkTemplateException, or ...