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 (
    1322, 1262, 1317, 1318, 1319, 1320, 1321, 
    1256, 1395, 1396, 1397, 1399, 1406, 
    1407, 1408, 1409, 1410, 1411, 1412, 
    1273, 1425, 1427, 1428, 1429, 1431, 
    1266, 1442, 1447, 1263, 1458, 4526, 
    4527, 4528, 4529, 4530, 4532, 4533, 
    4744, 4745, 4746, 4747, 4750, 4751, 
    4776, 4778, 4780, 4771, 4773, 4767, 
    4788, 4789, 4790
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00327

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "115.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": 128,
            "rows_produced_per_join": 128,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (1322,1262,1317,1318,1319,1320,1321,1256,1395,1396,1397,1399,1406,1407,1408,1409,1410,1411,1412,1273,1425,1427,1428,1429,1431,1266,1442,1447,1263,1458,4526,4527,4528,4529,4530,4532,4533,4744,4745,4746,4747,4750,4751,4776,4778,4780,4771,4773,4767,4788,4789,4790))",
            "cost_info": {
              "read_cost": "57.81",
              "eval_cost": "12.80",
              "prefix_cost": "70.61",
              "data_read_per_join": "2K"
            },
            "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": "32.00",
              "eval_cost": "0.64",
              "prefix_cost": "115.41",
              "data_read_per_join": "20K"
            },
            "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
1256 234,166,326M
1262 166,234,326M
1263 234,166,326M
1266 234,166,326M
1273 234,166,326M
1317 166,234,326M
1318 166,234,326M
1319 166,234,326M
1320 166,234,326M
1321 166,234,326M
1322 166,234,326M
1395 234,166,326M
1396 234,166,326M
1397 234,166,326M
1399 234,166,326M
1406 234,166,326M
1407 234,166,326M
1408 234,166,326M
1409 234,166,326M
1410 234,166,326M
1411 234,166,326M
1412 234,166,326M
1425 234,166,326M
1427 234,166,326M
1428 234,166,326M
1429 234,166,326M
1431 234,166,326M
1442 234,166,326M
1447 234,166,326M
1458 234,166,326M
4526 234,166,326M
4527 234,166,326M
4528 234,166,326M
4529 234,166,326M
4530 234,166,326M
4532 234,166,326M
4533 234,166,326M
4744 234,166,326M
4745 166,234,326M
4746 234,166,326M
4747 166,234,326M
4750 166,234,326M
4751 234,166,326M
4767 234,166,326M
4771 166,234,326M
4773 234,166,326M
4776 166,234,326M
4778 166,234,326M
4780 166,234,326M
4788 166,234,326M
4789 234,166,326M
4790 166,234,326M