Using get_term() in functions.php results in Invalid taxonomy error

It sounds like you are are using get_term() for a custom taxonomy. If you’re using get_term() inside functions.php and outside of a hooked function, that code is going to be run immediately when functions.php is loaded. Your custom taxonomy will not have been registered at this point, because that happens on the init hook.

Your code is working inside of your page template because WordPress has loaded the custom taxonomies at that point.

If you were to try something like $term = get_term( '2', 'category' ); (where 2 is a valid term ID) in functions.php, it would actually work, because WordPress loads built-in taxonomies in wp-settings.php (which is very early in the loading process) for backwards compatibility reasons. WordPress also registers default taxonomies on init, by the way. This is explained in the documentation block for create_initial_taxonomies() in /wp-includes/taxonomy.php.

Anyway, running get_term() outside of a hooked function in functions.php is not the right way to do it, and more code would be needed to help you further.