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 (
    339, 376, 1565, 1566, 1567, 1568, 1569, 
    1570, 1612, 1613, 1614, 1615, 1616, 
    1617, 1618, 5476, 5556, 1581, 1582, 
    1583, 1584, 1585, 349, 1586, 1587
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00764

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": 1079,
      "filtered": 100,
      "index_condition": "cscart_products_categories.product_id in (339,376,1565,1566,1567,1568,1569,1570,1612,1613,1614,1615,1616,1617,1618,5476,5556,1581,1582,1583,1584,1585,349,1586,1587)"
    },
    "table": {
      "table_name": "cscart_categories",
      "access_type": "eq_ref",
      "possible_keys": ["PRIMARY", "c_status"],
      "key": "PRIMARY",
      "key_length": "3",
      "used_key_parts": ["category_id"],
      "ref": ["herbaria_cscart_4_18.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
339 258,306,304,295,267,265,264,261,255,251,241,240,238,237,236,235,234,233,230,229,192,179,175,123,120,109,101,94,83,79,74,73,69,68,67,64,60,55,54,53,52,47,46,44,43,41,26,20,19,17,16,15,336,1M
349 330,228,313,306,304,23,295,269,265,246,241,222,201,192,179,120,83,74,64,61,54,50,42,41,67,81,337,217M
376 242,307,306,304,271,270,261,258,234,233,222,217,208,194,181,104,101,95,94,91,88,82,79,71,70,67,56,49,42,41,23,17,15,10,336,29,1M
1565 306,304,295,267,265,264,261,255,251,241,240,238,237,236,235,234,233,230,229,192,179,175,123,120,109,101,94,83,79,74,73,69,68,67,64,60,55,54,53,52,47,46,44,43,41,26,20,19,17,16,258,15,336,1M
1566 306,304,295,267,265,264,261,255,251,241,240,238,237,236,235,234,233,230,229,192,179,175,123,120,109,101,94,83,79,74,73,69,68,67,64,60,55,54,53,52,47,46,44,43,41,26,20,19,17,16,258,15,336,1M
1567 306,304,295,267,265,264,261,255,251,241,240,238,237,236,235,234,233,230,229,192,179,175,123,120,109,101,94,83,79,74,73,69,68,67,64,60,55,54,53,52,47,46,44,43,41,26,20,19,17,16,258,15,336,1M
1568 306,304,295,267,265,264,261,255,251,241,240,238,237,236,235,234,233,230,229,192,179,175,123,120,109,101,94,83,79,74,73,69,68,67,64,60,55,54,53,52,47,46,44,43,41,26,20,19,17,16,258,15,336,1M
1569 306,304,295,267,265,264,261,255,251,241,240,238,237,236,235,234,233,230,229,192,179,175,123,120,109,101,94,83,79,74,73,69,68,67,64,60,55,54,53,52,47,46,44,43,41,26,20,19,17,16,258,15,336,1M
1570 306,304,295,267,265,264,261,255,251,241,240,238,237,236,235,234,233,230,229,192,179,175,123,120,109,101,94,83,79,74,73,69,68,67,64,60,55,54,53,52,47,46,44,43,41,26,20,19,17,16,258,15,336,1M
1581 81,67,330,228,313,306,304,23,295,269,265,246,241,222,201,192,179,120,83,74,64,61,54,50,42,41,337,217M
1582 330,228,313,306,304,23,295,269,265,246,241,222,201,192,179,120,83,74,64,61,54,50,42,41,67,81,337,217M
1583 330,228,313,306,304,23,295,269,265,246,241,222,201,192,179,120,83,74,64,61,54,50,42,41,67,81,337,217M
1584 330,228,313,306,304,23,295,269,265,246,241,222,201,192,179,120,83,74,64,61,54,50,42,41,67,81,337,217M
1585 330,228,313,306,304,23,295,269,265,246,241,222,201,192,179,120,83,74,64,61,54,50,42,41,67,81,337,217M
1586 330,228,313,306,304,23,295,269,265,246,241,222,201,192,179,120,83,74,64,61,54,50,42,41,67,81,337,217M
1587 330,228,313,306,304,23,295,269,265,246,241,222,201,192,179,120,83,74,64,61,54,50,42,41,67,81,337,217M
1612 242,307,306,304,271,270,261,258,234,233,222,217,208,194,181,104,101,95,94,91,88,82,79,71,70,67,56,49,42,41,23,17,15,10,336,29,1M
1613 242,307,306,304,271,270,261,258,234,233,222,217,208,194,181,104,101,95,94,91,88,82,79,71,70,67,56,49,42,41,23,17,15,10,336,29,1M
1614 242,307,306,304,271,270,261,258,234,233,222,217,208,194,181,104,101,95,94,91,88,82,79,71,70,67,56,49,42,41,23,17,15,10,336,29,1M
1615 242,307,306,304,271,270,261,258,234,233,222,217,208,194,181,104,101,95,94,91,88,82,79,71,70,67,56,49,42,41,23,17,15,10,336,29,1M
1616 242,307,306,304,271,270,261,258,234,233,222,217,208,194,181,104,101,95,94,91,88,82,79,71,70,67,56,49,42,41,23,17,15,10,336,29,1M
1617 242,307,306,304,271,270,261,258,234,233,222,217,208,194,181,104,101,95,94,91,88,82,79,71,70,67,56,49,42,41,23,17,15,10,336,29,1M
1618 242,307,306,304,271,270,261,258,234,233,222,217,208,194,181,104,101,95,94,91,88,82,79,71,70,67,56,49,42,41,23,17,15,10,336,29,1M
5476 336,242,307,306,304,271,270,261,258,234,233,222,217,208,194,181,104,101,95,94,91,88,82,79,71,70,67,56,49,42,41,23,17,15,10,29,1M
5556 261,20,255,26,251,241,240,238,237,236,235,15,234,233,230,229,192,179,336,175,123,120,109,101,94,83,79,74,73,69,68,67,64,60,55,54,53,52,47,46,44,43,41,258,306,304,295,267,16,265,17,264,19,1M