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 (
    1975, 2305, 49192, 2303, 31965, 1972, 
    2304, 5829, 2302, 22143, 1976, 5830, 
    2299, 31960, 3641, 3639, 2295, 2298, 
    5826, 3640, 2297, 2300, 27366, 2306, 
    1973, 3642, 2301, 5827, 5825, 2296
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00942

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": 77,
          "filtered": 100,
          "index_condition": "cscart_products_categories.product_id in (1975,2305,49192,2303,31965,1972,2304,5829,2302,22143,1976,5830,2299,31960,3641,3639,2295,2298,5826,3640,2297,2300,27366,2306,1973,3642,2301,5827,5825,2296)"
        }
      },
      {
        "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": ["dev_db.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
1972 210,213,412,169M
1973 210,213,169M
1975 169,412,210M
1976 169,412,210M
2295 210,213,412,169M
2296 169M
2297 169M
2298 412,169M
2299 169M
2300 210,412,169M
2301 169M
2302 169M
2303 210,412,169M
2304 210,412,169M
2305 169,412,210M
2306 181M
3639 169,412,210M
3640 169,412,210M
3641 169,412,210M
3642 169,412,210M
5825 169M
5826 412,169M
5827 169M
5829 169,412,210M
5830 169,412,210M
22143 213,210,169M
27366 169M
31960 213,169M
31965 210,213,169M
49192 213,210,412,169M