Hi,
There is no such system. Regardless from where you reach the product page, HikaShop picks the "main category" of the product and then use the layout of that template, always.
That way, you can add several categories to a product and be sure that it's always the same layout that will be used.
So it's actually normal that it works like that and was made on purpose to be like that.
If you want to change that behavior, you'll have to edit the file "show" of the view "product" via the menu Display>Views.
There you can change the $this->productlayout value based on $this->categories and your custom needs.