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 (
    21351, 21291, 22158, 21296, 21307, 21352, 
    21287, 22159, 21297, 21342, 21353, 
    21288, 22175, 21298, 21343, 21354, 
    21289, 22177, 21299, 22152, 21344, 
    21355, 22151, 22160, 21300, 21345, 
    20221, 21356, 21488, 22161, 21301, 
    21346, 20222, 21357, 22153, 21552, 
    21302, 21347, 20223, 22154, 21292, 
    21553, 21303, 21348, 21514, 22155, 
    21293, 21304, 21349, 21286, 22156, 
    21294, 21305, 21350, 21290, 22157, 
    21295, 21306
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00091

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": 58,
          "filtered": 100,
          "index_condition": "cscart_products_categories.product_id in (21351,21291,22158,21296,21307,21352,21287,22159,21297,21342,21353,21288,22175,21298,21343,21354,21289,22177,21299,22152,21344,21355,22151,22160,21300,21345,20221,21356,21488,22161,21301,21346,20222,21357,22153,21552,21302,21347,20223,22154,21292,21553,21303,21348,21514,22155,21293,21304,21349,21286,22156,21294,21305,21350,21290,22157,21295,21306)"
        }
      },
      {
        "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
20221 961M
20222 961M
20223 961M
21286 961M
21287 961M
21288 961M
21289 961M
21290 961M
21291 961M
21292 961M
21293 961M
21294 961M
21295 961M
21296 961M
21297 961M
21298 961M
21299 961M
21300 961M
21301 961M
21302 961M
21303 961M
21304 961M
21305 961M
21306 961M
21307 961M
21342 961M
21343 961M
21344 961M
21345 961M
21346 961M
21347 961M
21348 961M
21349 961M
21350 961M
21351 961M
21352 961M
21353 961M
21354 961M
21355 961M
21356 961M
21357 961M
21488 961M
21514 961M
21552 961M
21553 961M
22151 961M
22152 961M
22153 961M
22154 961M
22155 961M
22156 961M
22157 961M
22158 961M
22159 961M
22160 961M
22161 961M
22175 961M
22177 961M