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 (
    623, 624, 704, 703, 663, 710, 709, 708, 
    707, 706, 719, 718, 717, 716, 715, 714, 
    713, 711, 666, 724, 723, 722, 721, 720, 
    726, 725, 727, 960, 961, 962, 963, 964
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00132

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "107.74"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "3.65"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 125,
            "rows_produced_per_join": 5,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "29.49",
              "eval_cost": "1.00",
              "prefix_cost": "30.49",
              "data_read_per_join": "20K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`cscart`.`cscart_categories`.`storefront_id` in (0,1)) and ((`cscart`.`cscart_categories`.`usergroup_ids` = '') or find_in_set(0,`cscart`.`cscart_categories`.`usergroup_ids`) or find_in_set(1,`cscart`.`cscart_categories`.`usergroup_ids`)) and (`cscart`.`cscart_categories`.`status` in ('A','H')))"
          }
        },
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "cscart.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 12,
            "rows_produced_per_join": 3,
            "filtered": "6.09",
            "index_condition": "(`cscart`.`cscart_products_categories`.`product_id` in (623,624,704,703,663,710,709,708,707,706,719,718,717,716,715,714,713,711,666,724,723,722,721,720,726,725,727,960,961,962,963,964))",
            "cost_info": {
              "read_cost": "61.60",
              "eval_cost": "0.73",
              "prefix_cost": "104.09",
              "data_read_per_join": "58"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
623 335,343,333M
624 335,343,333M
663 415,313M
666 415,312,313M
703 313M,415
704 415,313M
706 415,313M
707 415,313M
708 415,313M
709 415,313M
710 415,313M
711 313M,312,415
713 312,415,313M
714 312,415,313M
715 312,415,313M
716 312,415,313M
717 312,415,313M
718 313M,312,415
719 312,415,313M
720 415M
721 415M
722 415M
723 415M
724 415M
725 402M,312,313
726 402M,312,313
727 402M,312,313
960 333,335M,341
961 333,335M,341
962 333,335,342M
963 342M,333,335
964 342M,333,335