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 (
    55, 194, 298, 427, 428, 429, 430, 431, 
    506, 518, 519, 5473, 5474, 504, 1843, 
    1841, 1855, 1840, 1853, 486, 1854, 1842
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00478

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": 454,
      "filtered": 100,
      "index_condition": "cscart_products_categories.product_id in (55,194,298,427,428,429,430,431,506,518,519,5473,5474,504,1843,1841,1855,1840,1853,486,1854,1842)"
    },
    "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
55 261,257,249,243,241,240,237,107,100,75,48,44,27,26,20,18,16,306,1M
194 304,310,306,261,258,199,6,1,242M
298 267,261,259,306,241,238,237,236,235,234,233,227,226,93,89,85,82,80,79,75,67,57,56,43,217M
427 261,267,259,306,241,238,237,236,235,234,233,227,226,93,89,85,82,80,79,75,67,57,56,43,217M
428 261,267,259,306,241,238,237,236,235,234,233,227,226,93,89,85,82,80,79,75,67,57,56,43,217M
429 261,267,259,306,241,238,237,236,235,234,233,227,226,93,89,85,82,80,79,75,67,57,56,43,217M
430 261,267,259,306,241,238,237,236,235,234,233,227,226,93,89,85,82,80,79,75,67,57,56,43,217M
431 261,267,259,306,241,238,237,236,235,234,233,227,226,93,89,85,82,80,79,75,67,57,56,43,217M
486 83,87,70,90,81,77,76,107,88,95,47,46,94,67,306,261,258,241,236,233,75,73,44,20,1,61,242M
504 335,333,334,306,261,257,243,240,239,235,234,67,46,36,35,34,33,25,17,16,298,297,1M
506 261,257,249,243,241,240,237,107,100,75,48,44,27,26,20,18,16,306,1M
518 304,310,306,261,258,199,6,1,242M
519 304,310,306,261,258,199,6,1,242M
1840 83,87,70,90,81,77,76,107,88,95,47,46,94,67,306,261,258,241,236,233,75,73,44,20,1,61,242M
1841 83,87,70,90,81,77,76,107,88,95,47,46,94,67,306,261,258,241,236,233,75,73,44,20,1,61,242M
1842 83,87,70,90,81,77,76,107,88,95,47,46,94,67,306,261,258,241,236,233,75,73,44,20,1,61,242M
1843 83,87,70,90,81,77,76,107,88,95,47,46,94,67,306,261,258,241,236,233,75,73,44,20,1,61,242M
1853 335,333,334,306,261,257,243,240,239,235,234,67,46,36,35,34,33,25,17,16,298,297,1M
1854 335,333,334,306,261,257,243,240,239,235,234,67,46,36,35,34,33,25,17,16,298,297,1M
1855 335,333,334,306,261,257,243,240,239,235,234,67,46,36,35,34,33,25,17,16,298,297,1M
5473 83,61,1,20,44,73,75,233,236,241,258,261,306,67,94,46,47,95,88,107,76,77,81,90,70,87,242M
5474 297,298,16,17,25,33,34,35,36,46,67,234,235,239,240,243,257,261,306,334,333,335,1M