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 (
    127, 51325, 63, 51326, 135, 50984, 51450, 
    51451, 51343, 51342, 51341, 51340, 
    47, 136, 65, 42, 51376, 51377, 51378, 
    51379, 51380, 134
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00086

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "47.91"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 53,
            "rows_produced_per_join": 53,
            "filtered": "100.00",
            "index_condition": "(`test_uchur_k`.`cscart_products_categories`.`product_id` in (127,51325,63,51326,135,50984,51450,51451,51343,51342,51341,51340,47,136,65,42,51376,51377,51378,51379,51380,134))",
            "cost_info": {
              "read_cost": "24.06",
              "eval_cost": "5.30",
              "prefix_cost": "29.36",
              "data_read_per_join": "848"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        },
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "test_uchur_k.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 2,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "13.25",
              "eval_cost": "0.27",
              "prefix_cost": "47.91",
              "data_read_per_join": "14K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`test_uchur_k`.`cscart_categories`.`storefront_id` in (0,1)) and ((`test_uchur_k`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`test_uchur_k`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`test_uchur_k`.`cscart_categories`.`usergroup_ids`))) and (`test_uchur_k`.`cscart_categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
42 45,391,18M
47 45,23M
63 45,394,8M
65 45,25M
127 45,34M
134 10,45M
135 45,394,36M
136 45,394,37M
50984 45,10M
51325 45,34M
51326 45,394,36M
51340 45,23M
51341 45,23M
51342 45,23M
51343 45,23M
51376 45,391,18M
51377 45,391,18M
51378 391,45,18M
51379 391,45,18M
51380 391,45,18M
51450 45,10M
51451 45,10M