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 (
    18481, 18505, 18506, 18483, 18501, 18507, 
    18523, 18508, 18509, 18510, 18511, 
    18512, 18484, 18513, 18514, 18485, 
    18486, 18487, 18488, 18515, 18516, 
    18517, 18518, 18496, 18519, 18489, 
    18490, 18520, 18521, 18493, 18491, 
    18492, 18522
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00087

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": 33,
          "filtered": 100,
          "index_condition": "cscart_products_categories.product_id in (18481,18505,18506,18483,18501,18507,18523,18508,18509,18510,18511,18512,18484,18513,18514,18485,18486,18487,18488,18515,18516,18517,18518,18496,18519,18489,18490,18520,18521,18493,18491,18492,18522)"
        }
      },
      {
        "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
18481 821M
18483 821M
18484 821M
18485 821M
18486 821M
18487 821M
18488 821M
18489 821M
18490 821M
18491 821M
18492 821M
18493 821M
18496 821M
18501 821M
18505 1146M
18506 821M
18507 821M
18508 821M
18509 821M
18510 821M
18511 821M
18512 821M
18513 821M
18514 821M
18515 821M
18516 821M
18517 821M
18518 821M
18519 821M
18520 821M
18521 821M
18522 821M
18523 821M