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 (
    128, 51118, 51117, 51116, 51115, 51114, 
    51113, 51165, 51164, 51163, 51162, 
    51161, 52, 51183, 20, 51188, 51187, 
    51186, 51185, 51184, 51201, 51200, 
    51199, 51198, 51197, 51196, 51195, 
    131, 51231, 51230, 51229, 51228, 51227, 
    51226, 51225, 109, 51243, 51242, 51241, 
    51240, 51239, 36, 51253, 51252, 51251, 
    51250, 51249, 34, 51265, 51264, 51263, 
    51262, 51261, 51260, 51259, 110, 51273, 
    147, 51277, 51276, 51275, 51274, 51346, 
    118, 114, 84, 51352, 51351, 96
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00394

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "169.12"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "30.99"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 383,
            "rows_produced_per_join": 15,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "40.09",
              "eval_cost": "1.53",
              "prefix_cost": "41.62",
              "data_read_per_join": "81K"
            },
            "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')))"
          }
        },
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "test_uchur_k.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 18,
            "rows_produced_per_join": 30,
            "filtered": "11.24",
            "index_condition": "(`test_uchur_k`.`cscart_products_categories`.`product_id` in (128,51118,51117,51116,51115,51114,51113,51165,51164,51163,51162,51161,52,51183,20,51188,51187,51186,51185,51184,51201,51200,51199,51198,51197,51196,51195,131,51231,51230,51229,51228,51227,51226,51225,109,51243,51242,51241,51240,51239,36,51253,51252,51251,51250,51249,34,51265,51264,51263,51262,51261,51260,51259,110,51273,147,51277,51276,51275,51274,51346,118,114,84,51352,51351,96))",
            "cost_info": {
              "read_cost": "68.94",
              "eval_cost": "3.10",
              "prefix_cost": "138.14",
              "data_read_per_join": "495"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
20 43,9,40M
34 42,7,40M
36 43,7,40M
52 9,42,40M
84 42,28,394,40M
96 42,32,40M
109 42,7,40M
110 42,7,40M
114 6,42,40M
118 42,6,40M
128 43,10,40M
131 42,9,40M
147 7,42,40M
51113 10,43,40M
51114 10,43,40M
51115 10,43,40M
51116 10,43,40M
51117 10,43,40M
51118 10,43,40M
51161 9,42,40M
51162 9,42,40M
51163 9,42,40M
51164 9,42,40M
51165 42,9,40M
51183 9,43,40M
51184 9,43,40M
51185 9,43,40M
51186 9,43,40M
51187 9,43,40M
51188 9,43,40M
51195 9,42,40M
51196 42,9,40M
51197 9,42,40M
51198 9,42,40M
51199 9,42,40M
51200 9,42,40M
51201 9,42,40M
51225 7,42,40M
51226 7,42,40M
51227 7,42,40M
51228 7,42,40M
51229 7,42,40M
51230 7,42,40M
51231 7,42,40M
51239 7,43,40M
51240 7,43,40M
51241 7,43,40M
51242 7,43,40M
51243 7,43,40M
51249 7,42,40M
51250 7,42,40M
51251 7,42,40M
51252 7,42,40M
51253 7,42,40M
51259 7,42,40M
51260 7,42,40M
51261 7,42,40M
51262 7,42,40M
51263 7,42,40M
51264 7,42,40M
51265 7,42,40M
51273 7,42,40M
51274 42,7,40M
51275 42,7,40M
51276 42,7,40M
51277 42,7,40M
51346 6,42,40M
51351 32,42,40M
51352 32,42,40M