How to set foreign key on two tables in MySQL?

I am struggling in resolving a db design for MySQL 5.7 to solve the following scenario:

There are category dimensions that change each day, I store them in category_entities. They belong to a category which relates to a merchant and his products:

merchants

merchant_id | merchant
1           | amazon
2           | ebay

PK: merchant_id

products

prod_id    | merchant_id | product
1          | 1           | jumper big
2          | 1           | hat red
3          | 2           | shoe black

PK: merchant_id, prod_id

categories

cat_id     | merchant_id | category
1          | 1           | jumpers in green 
2          | 1           | hats for woman
3          | 1           | shoes
4          | 2           | jumpers 
5          | 2           | hats for children
6          | 2           | shoes

PK: cat_id

category_entities (30M rows)

cat_id | prod_id | characteristica | date
1      | 1       | 23              | 2021-01-07
2      | 2       | 22              | 2021-01-07
1      | 2       | 22              | 2021-01-08
2      | 3       | 01              | 2021-01-08
3      | 1       | 22              | 2021-01-08
4      | 2       | 01              | 2021-01-08

PK: cat_id, prod_id, date

So the category table defines what categories exists and the category_entities talbe shows the value for each day

How can I set a foreign key on the tables (categories, category_entities) on table products using prod_id, merchant_id. Those fields are the primary key of product.

I as reading about polymorphic assosiations but I am not sure this is one and how to solve this.