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 (
    2805, 2808, 3114, 3115, 3150, 3151, 3552, 
    3553, 4915, 4917, 4924, 4923, 4922, 
    4921, 4920, 4919, 4918, 4925, 4927, 
    4926, 4987, 4986, 4985, 4984, 4977, 
    4976, 4981, 4980, 4979, 4978, 4982, 
    4983, 5687, 5688, 5689, 5690, 5691, 
    5692, 5693, 5694, 6026, 6025, 6027, 
    6028, 6029, 6030
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00219

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "107.51"
    },
    "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": 120,
            "rows_produced_per_join": 120,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (2805,2808,3114,3115,3150,3151,3552,3553,4915,4917,4924,4923,4922,4921,4920,4919,4918,4925,4927,4926,4987,4986,4985,4984,4977,4976,4981,4980,4979,4978,4982,4983,5687,5688,5689,5690,5691,5692,5693,5694,6026,6025,6027,6028,6029,6030))",
            "cost_info": {
              "read_cost": "53.51",
              "eval_cost": "12.00",
              "prefix_cost": "65.51",
              "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": "30.00",
              "eval_cost": "0.60",
              "prefix_cost": "107.51",
              "data_read_per_join": "18K"
            },
            "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
2805 424,423,492,166M
2808 423,424,492,166M
3114 492,452,424,423,166M
3115 423,424,452,492,166M
3150 423,424,450,166M
3151 423,424,450,166M
3552 423,424,450,166M
3553 423,424,450,166M
4915 166,423,449M
4917 166,423,449M
4918 166,423,449M
4919 166,423,449M
4920 166,423,449M
4921 166,423,449M
4922 166,423,449M
4923 166,423,449M
4924 166,423,449M
4925 166,423,449M
4926 166,423,449M
4927 166,423,449M
4976 166,423,449M
4977 166,423,449M
4978 166,423,449M
4979 166,423,449M
4980 166,423,449M
4981 166,423,449M
4982 166,423,449M
4983 166,423,449M
4984 166,423,449M
4985 166,423,449M
4986 166,423,449M
4987 166,423,449M
5687 423,449,166M
5688 423,449,166M
5689 423,449,166M
5690 423,449,166M
5691 423,449,166M
5692 423,449,166M
5693 423,449,166M
5694 423,449,166M
6025 423,166,585M
6026 166,423,585M
6027 166,423,585M
6028 166,423,585M
6029 166,423,585M
6030 166,423,585M