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 (
    5584, 5481, 5489, 5428, 5524, 5591, 5511, 
    5419, 5495, 5423, 5424, 5480, 5486, 
    5657, 5546, 5543, 5440, 5547, 9547, 
    5438, 5443, 5476, 5542, 5548, 5592, 
    5585, 5649, 5447, 5529, 5439, 5659, 
    5602, 5496, 5656, 5475, 5433, 5498, 
    5603, 5432, 5514
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00288

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "92.41"
    },
    "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": 103,
            "rows_produced_per_join": 103,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (5584,5481,5489,5428,5524,5591,5511,5419,5495,5423,5424,5480,5486,5657,5546,5543,5440,5547,9547,5438,5443,5476,5542,5548,5592,5585,5649,5447,5529,5439,5659,5602,5496,5656,5475,5433,5498,5603,5432,5514))",
            "cost_info": {
              "read_cost": "46.06",
              "eval_cost": "10.30",
              "prefix_cost": "56.36",
              "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": 5,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "25.75",
              "eval_cost": "0.52",
              "prefix_cost": "92.41",
              "data_read_per_join": "16K"
            },
            "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
5419 473,577,474M
5423 577,578M
5424 577,578M
5428 466,372,574M
5432 466,372,574M
5433 466,372,574M
5438 466,372,574M
5439 466,372,574M
5440 466,372,574M
5443 466,372,574M
5447 466,372,574M
5475 466,372,574M
5476 466,372,574M
5480 466,372,575M
5481 466,372,575M
5486 466,372,575M
5489 466,372,575M
5495 466,372,575M
5496 466,372,573M
5498 466,372,573M
5511 466,372,573M
5514 466,372,573M
5524 466,372,576M
5529 466,372,573M
5542 553,250,552,554,372,556M
5543 553,250,552,554,372,556M
5546 553,250,552,554,372,556M
5547 553,250,552,554,372,556M
5548 553,250,552,554,372,556M
5584 572,372,582M
5585 466,372,573M
5591 466,372,573M
5592 466,372,573M
5602 466,372,573M
5603 466,372,573M
5649 372,384,460M
5656 372,384M
5657 372,384M
5659 372,384M
9547 577M