You don't need that pagecontents recordset on the sub-page because we are getting the category name from the Categories recordset.
I've already given you the update the .htaccess for the product details page... now you can filter the recordset on the product details page using the perm url parameter filtered against the products permalink column.
You should be able to use INNER join to join the products table to the productcategories table and the parent categories in a new recodset to return all of the subcategories filtering by the products permalink. That query will look something like:
$AllSubs = new WA_MySQLi_RS("AllSubs",$DBConnection,1);
$AllSubs->setQuery("SELECT productcategories.*, catParent.CategoryPermalink as ParentPermalink FROM productcategories INNER JOIN productcategories AS catParent ON catParent.CategoryID = productcategories.CategoryParentID WHERE catParent.CategoryID = (SELECT CategoryParentID FROM products INNER JOIN productcategories ON CategoryID = ProductCategoryID WHERE ProductPermalink = ?) AND Live = 1");
$AllSubs->bindParam("s", "".(isset($_GET['perm'])?$_GET['perm']:"") ."", "-1"); //paramPermalink
(my column and table names may be off since I'm not looking at your database, but that is the idea)