Style product detail page with custom CSS in woocommerce

Try adding classes, instead of restricting the CSS to certain pages.

You should be looking for classes that will allow you to apply your styles to those pages only. Usually the CSS for the entire site will be loaded at once and kept in the cache. So don’t try to load the styles only on certain pages, instead provide styles that override existing styles only on the pages you want to modify.

Check the body_class function, it produces the classes you need may on the <body> tag already.

And if that is not enough, try changing the template to output the category as a class name.

Also, you should not just inject a stylesheet into the head, you should use wp_enqueue_script to add new styles, but you shouldn’t really need to do that either.