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 (
    8562, 8563, 8564, 8565, 8619, 8621, 8622, 
    8623, 8624, 8625, 8918, 8919, 8920, 
    8627, 8631, 8632, 8633, 8692, 8655, 
    8656, 8657, 8658, 8659, 8660, 8663, 
    8664, 8665, 8666, 8667, 8668, 8935, 
    8568, 8685, 8560, 8686, 8689, 8690, 
    8691, 8731, 8733, 8732, 8734, 8735, 
    8736, 8739, 8740, 8776, 8777, 8779, 
    8780, 8781, 8782, 8838, 8840, 8916, 
    8917, 8748, 8927, 8933, 8934, 8936, 
    8937, 8939, 8940, 8941, 8943
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00139

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "69.31"
    },
    "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": 66,
            "rows_produced_per_join": 66,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (8562,8563,8564,8565,8619,8621,8622,8623,8624,8625,8918,8919,8920,8627,8631,8632,8633,8692,8655,8656,8657,8658,8659,8660,8663,8664,8665,8666,8667,8668,8935,8568,8685,8560,8686,8689,8690,8691,8731,8733,8732,8734,8735,8736,8739,8740,8776,8777,8779,8780,8781,8782,8838,8840,8916,8917,8748,8927,8933,8934,8936,8937,8939,8940,8941,8943))",
            "cost_info": {
              "read_cost": "39.61",
              "eval_cost": "6.60",
              "prefix_cost": "46.21",
              "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": 3,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "16.50",
              "eval_cost": "0.33",
              "prefix_cost": "69.31",
              "data_read_per_join": "10K"
            },
            "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
8560 658M
8562 658M
8563 658M
8564 658M
8565 658M
8568 658M
8619 658M
8621 658M
8622 658M
8623 658M
8624 658M
8625 658M
8627 658M
8631 658M
8632 658M
8633 658M
8655 658M
8656 658M
8657 658M
8658 658M
8659 658M
8660 658M
8663 658M
8664 658M
8665 658M
8666 658M
8667 658M
8668 658M
8685 658M
8686 658M
8689 658M
8690 658M
8691 658M
8692 658M
8731 658M
8732 658M
8733 658M
8734 658M
8735 658M
8736 658M
8739 658M
8740 658M
8748 658M
8776 658M
8777 658M
8779 658M
8780 658M
8781 658M
8782 658M
8838 658M
8840 658M
8916 658M
8917 658M
8918 658M
8919 658M
8920 658M
8927 658M
8933 658M
8934 658M
8935 658M
8936 658M
8937 658M
8939 658M
8940 658M
8941 658M
8943 658M