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 (
    5750, 7013, 5739, 5727, 4432, 1553, 2574, 
    1, 228, 247, 944, 478, 8, 985, 3754, 525, 
    2478, 1552, 10284, 6151, 1274, 908, 
    1930, 1557, 1554, 1560, 3452, 4009, 
    1556, 2527, 1561, 1134, 5696, 2088, 
    4022, 2490, 9, 2698, 1406, 5721
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00292

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "109.21"
    },
    "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": 124,
            "rows_produced_per_join": 124,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (5750,7013,5739,5727,4432,1553,2574,1,228,247,944,478,8,985,3754,525,2478,1552,10284,6151,1274,908,1930,1557,1554,1560,3452,4009,1556,2527,1561,1134,5696,2088,4022,2490,9,2698,1406,5721))",
            "cost_info": {
              "read_cost": "53.41",
              "eval_cost": "12.40",
              "prefix_cost": "65.81",
              "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": "31.00",
              "eval_cost": "0.62",
              "prefix_cost": "109.21",
              "data_read_per_join": "19K"
            },
            "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
1 174,166,372,453,454,190M
8 166,174,372,453,454,190M
9 174,166,372,454,453,190M
228 453,454,372,174,166,190M
247 322,166,340M
478 166,234,235M
525 234,166,235M
908 329,166,344M
944 166,234,235M
985 166,234,235M
1134 322,166,323M
1274 320,166,325M
1406 234,166,326M
1552 412,407,402,359,328,166,360M
1553 407,402,359,328,166,412,360M
1554 407,412,402,359,328,166,360M
1556 407,412,402,359,328,166,360M
1557 412,407,402,359,328,166,360M
1560 412,407,402,359,328,166,360M
1561 412,407,402,359,328,166,360M
1930 167,166,356M
2088 371,250,397M
2478 166,234,236M
2490 166,234,236M
2527 234,166,236M
2574 320,166,339M
2698 450,424,423,166M
3452 458,250,485M
3754 167,166,356M
4009 371,250,394M
4022 167,166,356M
4432 320,166,321M
5696 423,449,166M
5721 423,585,166M
5727 234,166,235M
5739 234,166,235M
5750 235M
6151 423,585,166M
7013 235M
10284 235M