SELECT 
  products_categories.product_id, 
  GROUP_CONCAT(
    IF(
      products_categories.link_type = "M", 
      CONCAT(
        products_categories.category_id, 
        "M"
      ), 
      products_categories.category_id
    )
  ) AS category_ids 
FROM 
  products_categories 
  INNER JOIN categories ON categories.category_id = products_categories.category_id 
  AND categories.storefront_id IN (0, 1) 
  AND (
    categories.usergroup_ids = '' 
    OR FIND_IN_SET(0, categories.usergroup_ids) 
    OR FIND_IN_SET(1, categories.usergroup_ids)
  ) 
  AND categories.status IN ('A', 'H') 
WHERE 
  products_categories.product_id IN (
    5978, 2760, 758, 764, 1352, 1390, 2596, 
    2599, 1356, 2595, 1395, 2601, 2600, 
    2598, 1379, 5817, 2768, 5814, 1378, 
    2772, 5843, 5854, 3413, 5956, 5910, 
    3329, 3377, 2543, 5861, 5839, 5830, 
    5801, 5804, 5815, 5849, 5806, 5836, 
    3591, 3374, 5808, 5809, 3409, 6004, 
    5920, 5879, 3403, 5885, 5911
  ) 
GROUP BY 
  products_categories.product_id

Query time 0.00159

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "75.68"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "link_type",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 137,
            "rows_produced_per_join": 137,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "14.03",
              "eval_cost": "13.70",
              "prefix_cost": "27.73",
              "data_read_per_join": "2K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`goimagine`.`products_categories`.`product_id` in (5978,2760,758,764,1352,1390,2596,2599,1356,2595,1395,2601,2600,2598,1379,5817,2768,5814,1378,2772,5843,5854,3413,5956,5910,3329,3377,2543,5861,5839,5830,5801,5804,5815,5849,5806,5836,3591,3374,5808,5809,3409,6004,5920,5879,3403,5885,5911))"
          }
        },
        {
          "table": {
            "table_name": "categories",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "goimagine.products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 6,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "34.25",
              "eval_cost": "0.69",
              "prefix_cost": "75.68",
              "data_read_per_join": "17K"
            },
            "used_columns": [
              "category_id",
              "usergroup_ids",
              "status",
              "storefront_id"
            ],
            "attached_condition": "((`goimagine`.`categories`.`storefront_id` in (0,1)) and ((`goimagine`.`categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`goimagine`.`categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`goimagine`.`categories`.`usergroup_ids`))) and (`goimagine`.`categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
758 2,2069,150M
764 2,1977,150M
1352 2,1977,150M
1356 2,2066,147M
1378 2,2066,147M
1379 2,2066,147M
1390 2,2067,150M
1395 2,2067,150M
2543 2,2066,147M
2595 2,2071,149M
2596 2,2071,149M
2598 2,1977,150M
2599 2,1977,150M
2600 2,1977,150M
2601 2,1977,150M
2760 150,2M
2768 2,1977,150M
2772 2,2068,150M
3329 2,2067,150M
3374 2,2067,150M
3377 2,2067,150M
3403 2,2067,150M
3409 150,2067,17M
3413 150,1977,17M
3591 150,1977,17M
5801 147,2066,17M
5804 2069,150M
5806 150,8649,17M
5808 150,2069,17M
5809 150,8649,17M
5814 150,1977,17M
5815 150,2069,17M
5817 152,2070,17M
5830 150,8649,17M
5836 150,2068,17M
5839 2072,16M
5843 150,2068,17M
5849 2069,150M
5854 2,1977,150M
5861 150,2068,17M
5879 150,2068,17M
5885 17,1977,8M
5910 150,2067,17M
5911 150,1977,17M
5920 17,1977,8M
5956 2072,16M
5978 2069,150M
6004 2072,16M