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 (
    4340, 2364, 13765, 13826, 13993, 2218, 
    2349, 2178, 2177, 11786, 2827, 2640, 
    2312, 2309, 2310, 2311, 3236, 4344, 
    3221, 3225, 3218, 3246, 3222, 4347, 
    3242, 12675, 11361, 12647, 12880, 12670
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00050

JSON explain

{
  "query_block": {
    "select_id": 1,
    "table": {
      "table_name": "cscart_products_categories",
      "access_type": "range",
      "possible_keys": ["PRIMARY", "pt"],
      "key": "pt",
      "key_length": "3",
      "used_key_parts": ["product_id"],
      "rows": 34,
      "filtered": 100,
      "index_condition": "cscart_products_categories.product_id in (4340,2364,13765,13826,13993,2218,2349,2178,2177,11786,2827,2640,2312,2309,2310,2311,3236,4344,3221,3225,3218,3246,3222,4347,3242,12675,11361,12647,12880,12670)"
    },
    "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": ["ymonline_livedata.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
2177 357M
2178 357M
2218 357M
2309 357M
2310 357M
2311 357M
2312 357M
2349 357M
2364 355M
2640 356M
2827 356M
3218 392M
3221 392M
3222 392M
3225 392M
3236 392M
3242 392M
3246 392M
4340 355M
4344 392M
4347 392M
11361 392M
11786 356M
12647 392M
12670 392M
12675 392M
12880 392M
13765 355,265M
13826 355,265M
13993 355,265M