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 (
    23838, 23831, 23839, 23832, 23840, 23833, 
    23841, 23834, 23842, 21580, 21581, 
    21582, 21140, 21141, 21142, 21143, 
    21535, 21145, 21146, 21147, 21149, 
    21150, 21151, 21152
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00067

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 (23838,23831,23839,23832,23840,23833,23841,23834,23842,21580,21581,21582,21140,21141,21142,21143,21535,21145,21146,21147,21149,21150,21151,21152)"
        }
      },
      {
        "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
21140 1016M
21141 1016M
21142 1016M
21143 1016M
21145 1016M
21146 1016M
21147 1016M
21149 1016M
21150 1016M
21151 1016M
21152 1016M
21535 1016M
21580 960M
21581 960M
21582 960M
23831 960M
23832 960M
23833 960M
23834 960M
23838 960M
23839 960M
23840 960M
23841 960M
23842 960M