Another way to look at the master_categories_id is to think of your Categories as more than just navigation to Products ...

If a Product belongs to 1 Category ... then that Category will have a categories_id that will match the master_categories_id ...

If a Product belongs to 2 or more Categories ... then only 1 of the 2 Categories can "own" the Linked Product ... it is the Category that "owns" the Product that is the categories_id for the master_categories_id ...

The purpose of that is for when it is not known where to go in navigation or for pricing information, such as SaleMaker, etc.

When navigating through the Categories, the immediate Category is known, as torvista has indicated, by the $cPath ...

To further specify the immediate Category there is the $current_category_id ... which helps in directing Products to the right Category ...

However, sometimes, the Category ... $cPath or $current_category_id ... is not known such as on a search or random creation of Products for display ...

This is where the $master_categories_id comes in ...

If you do not use Linked Products, this is simple to fix, by going to the Tools ... Store Manager ... and using the:
Reset ALL Products Master Categories ID
to be used for Linked Products and Pricing: Reset
Which you then want to follow up with:
Update ALL Products Price Sorter
to be able to sort by displayed prices: Update
The Products Price Sorter is used to help with sorting by price without having to do all kinds of calculations in the Catalog, as this is kept current in the Admin, as Products are added/edited ...

If you have Linked Products, then the master_categories_id may not be set right by using the update in the Store Manager, as it is updating based on the first categories_id that is found in the products_to_categories table ... and that table is ordered by categories_id ...

So if a Linked Product is linked to categories_id 23 and then to categories_id 3 ... categories_id 3 would be picked for updating the master_categories_id ...

Now, if you can run the Update Master Categories ID and then go to Catalog ... Categories/Products ... you will see an C for Copy on the Products ... hit the Multiple Categories Link Manager ...

At the bottom of the screen, you will see a place to update all of the Products in a Category to use that categories_id as its master_categories_id ...
Reset ALL Products in the selected Category to use the selected Category as the new Master Categories ID ...
Example: Resetting Category 22 would set ALL Products in Category 22 to use Category 22 as the Master Category ID
Reset the Master Categories ID for All Products in Category:
You can always set the master_categories_id yourself when editing the Product ...

NOTE: the option for setting the master_categories_id is only available if the Product is in 2 or more Categories and then you can only choose from those Categories ...

NOTE: always backup your database before using these features ...

NOTE: it is better to have a wrong master_categories_id than no master_categories_id where the master_categories_id is set to 0 ... you can always clean these up ...