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 (
    1128, 1127, 1126, 1125, 1124, 1123, 1139, 
    1138, 1137, 1136, 1135, 1134, 1133, 
    1132, 1131, 1130, 1129, 827, 1141, 851, 
    9602, 9603, 9604, 9615, 9646, 9647, 
    9648, 9649, 9653, 9654, 9655, 9656, 
    9657, 9658, 9659, 9660, 9869, 9868, 
    9870, 9871, 9874, 9875, 9877, 9878, 
    9881, 9882, 9884, 9885
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00207

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "73.61"
    },
    "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": 77,
            "rows_produced_per_join": 77,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (1128,1127,1126,1125,1124,1123,1139,1138,1137,1136,1135,1134,1133,1132,1131,1130,1129,827,1141,851,9602,9603,9604,9615,9646,9647,9648,9649,9653,9654,9655,9656,9657,9658,9659,9660,9869,9868,9870,9871,9874,9875,9877,9878,9881,9882,9884,9885))",
            "cost_info": {
              "read_cost": "38.96",
              "eval_cost": "7.70",
              "prefix_cost": "46.66",
              "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": "19.25",
              "eval_cost": "0.39",
              "prefix_cost": "73.61",
              "data_read_per_join": "12K"
            },
            "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
827 166,322,323M
851 322,166,323M
1123 166,322,323M
1124 166,322,323M
1125 166,322,323M
1126 322,166,323M
1127 166,322,323M
1128 166,322,323M
1129 166,322,323M
1130 166,322,323M
1131 166,322,323M
1132 166,322,323M
1133 166,322,323M
1134 322,166,323M
1135 166,322,323M
1136 166,322,323M
1137 166,322,323M
1138 166,322,323M
1139 166,322,323M
1141 166,322,323M
9602 323M
9603 323M
9604 323M
9615 323M
9646 323M
9647 323M
9648 323M
9649 323M
9653 323M
9654 323M
9655 323M
9656 323M
9657 323M
9658 323M
9659 323M
9660 323M
9868 323M
9869 323M
9870 323M
9871 323M
9874 323M
9875 323M
9877 323M
9878 323M
9881 323M
9882 323M
9884 323M
9885 323M