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 (
    12520, 12497, 12505, 12502, 12504, 10847, 
    13152, 10846, 10845, 10844, 10843, 
    10842, 10841, 10840, 10839, 10838, 
    10837, 10836, 10835, 10834, 10833, 
    10832, 10831, 10830, 10829, 10828, 
    10827, 12642, 12648, 12651, 12645, 
    12644
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00221

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": 37,
      "filtered": 100,
      "index_condition": "cscart_products_categories.product_id in (12520,12497,12505,12502,12504,10847,13152,10846,10845,10844,10843,10842,10841,10840,10839,10838,10837,10836,10835,10834,10833,10832,10831,10830,10829,10828,10827,12642,12648,12651,12645,12644)"
    },
    "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": ["noframes_angrybeaver.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
10827 1676M
10828 1676M
10829 1685M
10830 1685M
10831 1685M
10832 1685M
10833 1685M
10834 1685M
10835 1685M
10836 1685M
10837 1685M
10838 1685M
10839 1685M
10840 667M
10841 667M
10842 667M
10843 667M
10844 667M
10845 667M
10846 667M
10847 667M
12497 275M
12502 275M
12504 275M
12505 275M
12520 275M
12642 277,267,285,270M
12644 267,277,285,270M
12645 285,270,277,267M
12648 267,285,277,270M
12651 270,277,285,267M
13152 667M