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, 
  product_position_source.position AS position 
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.status IN ('A', 'H') 
  LEFT JOIN cscart_products_categories AS product_position_source ON cscart_products_categories.product_id = product_position_source.product_id 
  AND product_position_source.category_id = 2504 
WHERE 
  cscart_products_categories.product_id IN (
    64396, 65422, 65423, 65426, 65427, 65428, 
    65429, 65430, 65431, 65432, 65434, 
    65435, 65436, 65438, 65439, 65440, 
    65441, 65442, 65443, 65444, 65445, 
    65446, 65447, 65448
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00660

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "68.43"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "link_type",
              "pt",
              "idx_product_category_lookup",
              "idx_products_categories_composite"
            ],
            "key": "idx_products_categories_composite",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 48,
            "rows_produced_per_join": 48,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "5.28",
              "eval_cost": "4.80",
              "prefix_cost": "10.08",
              "data_read_per_join": "768"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`cscart_db`.`cscart_products_categories`.`product_id` in (64396,65422,65423,65426,65427,65428,65429,65430,65431,65432,65434,65435,65436,65438,65439,65440,65441,65442,65443,65444,65445,65446,65447,65448))"
          }
        },
        {
          "table": {
            "table_name": "product_position_source",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "pt",
              "idx_product_category_lookup",
              "idx_products_categories_composite"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id",
              "product_id"
            ],
            "key_length": "6",
            "ref": [
              "const",
              "cscart_db.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 48,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "36.75",
              "eval_cost": "4.80",
              "prefix_cost": "51.63",
              "data_read_per_join": "768"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        },
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "p_category_id",
              "idx_categories_storefront_status",
              "idx_categories_usergroup_status",
              "idx_categories_status_id_path"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "cscart_db.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 39,
            "filtered": "81.96",
            "cost_info": {
              "read_cost": "12.00",
              "eval_cost": "3.93",
              "prefix_cost": "68.43",
              "data_read_per_join": "110K"
            },
            "used_columns": [
              "category_id",
              "status",
              "storefront_id"
            ],
            "attached_condition": "((`cscart_db`.`cscart_categories`.`storefront_id` in (0,1)) and (`cscart_db`.`cscart_categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
64396 2517M,2518
65422 2510,2523M
65423 2510,2523M
65426 2510,2523M
65427 2510,2523M
65428 2506,2523M
65429 2506,2523M
65430 2506,2523M
65431 2506,2523M
65432 2506,2523M
65434 2510,2523M
65435 2510,2523M
65436 2510,2523M
65438 2510,2523M
65439 2510,2523M
65440 2510,2523M
65441 2510,2523M
65442 2510,2523M
65443 2510,2523M
65444 2510,2523M
65445 2510,2523M
65446 2510,2523M
65447 2510,2523M
65448 2510,2523M