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 (
    2574, 247, 2478, 908, 2527, 2490, 2372, 
    8483, 2509, 2892, 2896, 2471, 2576, 
    2902, 2395, 2620, 2359, 2340, 2502, 
    2473, 2508, 2565, 2906, 2580, 2638, 
    2550, 2275, 2363, 2599, 2399, 2352, 
    2503, 2602, 2459, 2339, 2360, 2572, 
    2253, 2540, 2107
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00266

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "106.81"
    },
    "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": 121,
            "rows_produced_per_join": 121,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (2574,247,2478,908,2527,2490,2372,8483,2509,2892,2896,2471,2576,2902,2395,2620,2359,2340,2502,2473,2508,2565,2906,2580,2638,2550,2275,2363,2599,2399,2352,2503,2602,2459,2339,2360,2572,2253,2540,2107))",
            "cost_info": {
              "read_cost": "52.36",
              "eval_cost": "12.10",
              "prefix_cost": "64.46",
              "data_read_per_join": "1K"
            },
            "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": [
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 6,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "30.25",
              "eval_cost": "0.61",
              "prefix_cost": "106.81",
              "data_read_per_join": "18K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`storefront_id` in (0,1)) and ((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`))) and (`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
247 322,166,340M
908 329,166,344M
2107 322,166,340M
2253 329,166,344M
2275 438,328,402,250,166,439M
2339 424,423,452,166M
2340 424,423,450,166M
2352 424,423,450,166M
2359 329,455,453,372,337,174,166,527M
2360 166,378,443M
2363 166,329,347M
2372 329,166,347M
2395 308,350,386,250,166,382M
2399 308,350,386,250,166,382M
2459 372,166,453,454,174,190M
2471 234,166,236M
2473 166,234,236M
2478 166,234,236M
2490 166,234,236M
2502 166,234,236M
2503 166,234,236M
2508 320,166,339M
2509 166,320,339M
2527 234,166,236M
2540 166,234,236M
2550 166,234,236M
2565 166,234,236M
2572 320,166,339M
2574 320,166,339M
2576 234,166,236M
2580 166,234,236M
2599 166,234,236M
2602 166,234,236M
2620 166,234,236M
2638 166,320,339M
2892 372,384,459M
2896 384,372,459M
2902 372,384,460M
2906 466,372,467M
8483 454,166,372,453,174,190M