How come I cannot fetch the name of the taxonomy term from term id?
Currently your problem is that you're trying to call entity class methods on a stdClass object - directly querying the database means you're not using the API any more, the results you get aren't entities.

Unless there's a particular reason to do so, though, you shouldn't have to do it that way.

For example, the same query can be executed like this through the API:

$terms = \Drupal::entityTypeManager()
  -&gt;getStorage('taxonomy_term')
  -&gt;loadByProperties(['vid' =&gt; 'term_category']);

foreach ($terms as $term) {
  $name = $term-&gt;getName();
}


It's quicker (loading in one go, not single loads in a loop), fewer lines of code, and when you bring caching into it, probably more performant.