SELECT 
  cscart_products_categories.product_id, 
  GROUP_CONCAT(
    IF(
      cscart_products_categories.link_type = "M", 
      CONCAT(
        cscart_products_categories.category_id, 
        "M"
      ), 
      cscart_products_categories.category_id
    )
  ) AS category_ids 
FROM 
  cscart_products_categories 
  INNER JOIN cscart_categories ON cscart_categories.category_id = cscart_products_categories.category_id 
  AND cscart_categories.storefront_id IN (0, 1) 
  AND (
    cscart_categories.usergroup_ids = '' 
    OR FIND_IN_SET(
      0, cscart_categories.usergroup_ids
    ) 
    OR FIND_IN_SET(
      1, cscart_categories.usergroup_ids
    )
  ) 
  AND cscart_categories.status IN ('A', 'H') 
WHERE 
  cscart_products_categories.product_id IN (
    19054, 19052, 19051, 19102, 19053, 19514, 
    19055, 19067, 19058, 20730, 19059, 
    19821, 22500, 22501, 22502, 22503, 
    22504, 22505, 19061, 22080, 20950, 
    20951, 20952, 20953, 19057, 7176, 19136, 
    20790, 19060, 19373, 19062
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00099

JSON explain

{
  "query_block": {
    "select_id": 1,
    "nested_loop": [
      {
        "table": {
          "table_name": "cscart_products_categories",
          "access_type": "range",
          "possible_keys": ["PRIMARY", "pt"],
          "key": "pt",
          "key_length": "3",
          "used_key_parts": ["product_id"],
          "rows": 37,
          "filtered": 100,
          "index_condition": "cscart_products_categories.product_id in (19054,19052,19051,19102,19053,19514,19055,19067,19058,20730,19059,19821,22500,22501,22502,22503,22504,22505,19061,22080,20950,20951,20952,20953,19057,7176,19136,20790,19060,19373,19062)"
        }
      },
      {
        "table": {
          "table_name": "cscart_categories",
          "access_type": "eq_ref",
          "possible_keys": ["PRIMARY", "c_status", "p_category_id"],
          "key": "PRIMARY",
          "key_length": "3",
          "used_key_parts": ["category_id"],
          "ref": ["lillyshop_lillyshop.cscart_products_categories.category_id"],
          "rows": 1,
          "filtered": 100,
          "attached_condition": "cscart_categories.storefront_id in (0,1) and (cscart_categories.usergroup_ids = '' or find_in_set(0,cscart_categories.usergroup_ids) or find_in_set(1,cscart_categories.usergroup_ids)) and cscart_categories.`status` in ('A','H')"
        }
      }
    ]
  }
}

Result

product_id category_ids
7176 839M
19051 839M
19052 839M
19053 839M
19054 839M
19055 839M
19057 839M
19058 839M
19059 839M
19060 839M
19061 839M
19062 839M
19067 839M
19102 839M
19136 839M
19373 839M
19514 839M
19821 839M
20730 839M
20790 839M
20950 839M
20951 839M
20952 839M
20953 839M
22080 839M
22500 839M
22501 839M
22502 839M
22503 839M
22504 839M
22505 839M