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 (
    40437, 40451, 2320, 2319, 48846, 40445, 
    40442, 47024, 41293, 40446, 47020, 
    47023, 47022, 40443, 40449, 40448, 
    40447, 49811, 40444, 41292, 40436, 
    47012, 40450, 41291, 41294, 40435, 
    47014, 40438, 47015, 40441
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00372

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": 80,
          "filtered": 100,
          "index_condition": "cscart_products_categories.product_id in (40437,40451,2320,2319,48846,40445,40442,47024,41293,40446,47020,47023,47022,40443,40449,40448,40447,49811,40444,41292,40436,47012,40450,41291,41294,40435,47014,40438,47015,40441)"
        }
      },
      {
        "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": ["dev_db.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
2319 409,152M
2320 409,152M
40435 209,409,149M
40436 409,149M
40437 409,149M
40438 409,149M
40441 409,149M
40442 409,149M
40443 409,149M
40444 409,149M
40445 409,149M
40446 409,149M
40447 110,409,149M
40448 409,149M
40449 209,409,149M
40450 209,409,149M
40451 210,209,409,149M
41291 209,210,142M
41292 209,210,142M
41293 209,210,142M
41294 209,210,142M
47012 210,141M
47014 210,209,141M
47015 210,141M
47020 142M
47022 209,210,142M
47023 99,142,209,210M
47024 142,209,210M
48846 209,409,153M
49811 142,209,210,213M