Get the vocabulary ID by term object?
You should be able to use the getVocabularyId() function on the term object like:
$vocabulary_id = $term-&gt;getVocabularyId();

See https://api.drupal.org/api/drupal/core%21modules%21taxonomy%21src%21Entity%21Term.php/function/Term%3A%3AgetVocabularyId/8.2.x.