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 (
    2187, 2244, 2172, 2171, 1668, 8586, 8372, 
    2222, 2175, 2228, 2220, 2177, 2230, 
    2226, 1667, 2221, 2179, 1666, 8240, 
    2183, 8813, 2176, 8433, 2224, 2195, 
    2225, 8514, 2189, 2196, 2186, 2180, 
    2178, 2191, 2170, 2181, 2190, 2185, 
    2198, 2182, 2188
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00233

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "125.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": 144,
            "rows_produced_per_join": 144,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (2187,2244,2172,2171,1668,8586,8372,2222,2175,2228,2220,2177,2230,2226,1667,2221,2179,1666,8240,2183,8813,2176,8433,2224,2195,2225,8514,2189,2196,2186,2180,2178,2191,2170,2181,2190,2185,2198,2182,2188))",
            "cost_info": {
              "read_cost": "60.41",
              "eval_cost": "14.40",
              "prefix_cost": "74.81",
              "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": 7,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "36.00",
              "eval_cost": "0.72",
              "prefix_cost": "125.21",
              "data_read_per_join": "22K"
            },
            "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
1666 250,380M
1667 380,250M
1668 452,424,423,166,492M
2170 350,308,386,250,166,382M
2171 386,350,308,250,166,382M
2172 386,350,308,250,166,382M
2175 386,350,308,250,166,382M
2176 386,350,308,250,166,382M
2177 386,350,308,250,166,382M
2178 386,350,308,250,166,382M
2179 250,166,386,350,308,382M
2180 386,350,308,250,166,382M
2181 386,350,308,250,166,382M
2182 386,350,308,250,166,382M
2183 386,350,308,250,166,382M
2185 385,308,350,250,166,381M
2186 385,308,350,250,166,381M
2187 385,308,350,250,166,381M
2188 385,308,350,250,166,381M
2189 385,308,350,250,166,381M
2190 385,308,350,250,166,381M
2191 385,308,350,250,166,381M
2195 426,423,166M
2196 426,423,166M
2198 425,423,166M
2220 250,336M
2221 424,423,451,166M
2222 424,423,451,166M
2224 424,423,451,166M
2225 424,423,452,166M
2226 424,423,450,166M
2228 166,424,450,423M
2230 424,423,450,166M
2244 166,378,432M
8240 492,657M
8372 423,657M
8433 464M
8514 423,657M
8586 423,657M
8813 546,568,343M