How do action and filter hooks understand where to look for the core function that we hooked our function to them

I think you may be looking at this the wrong way. It doesn’t need to look for the $tag function anywhere in core (or anywhere else for that matter). That function needs to already be loaded in the current sequence. As long as whatever file that contains your custom function is loaded at the time the action/filter is triggered, then your function can run (because it is in memory at that time) – otherwise, you’ll get an error since that function will be undefined.

Here’s a practical discussion of what I’m talking about. If you apply something in your theme’s functions.php file that is hooked to plugins_loaded, your function will never fire (even though it’s right there in functions.php) because the action has already passed by the time the functions.php file is loaded. You need a later action.

Or another example would that you need to make sure the file containing your function is actually loaded so that when your action or filter call is triggered that the file containing the function is loaded into memory. For example, if you have developed a plugin that consists of multiple files and in the main plugin file that gets loaded has a filter that triggers “my_cool_filter_function()” but you never bothered to include() or require() that file in your sequence, then the function will throw an undefined error because the function does not exist when the filter is triggered. However, as long as you’ve run include() (or require()) to load that file, then you’ll be fine because my_cool_filter_function() will be available to be run.