Only another microcontroller from the same manufacturer and family could have the same pinout and be compatible with the microcontroller's peripherals. The problem is that if that reference is not in stock, probably no other will be, due to the current world crisis of semiconductors.
I have replaced Kinetis MK66 LQFP144 with RT1064 BGA, both from NXP although from very different families, they only share that they are both ARM and use the same MCUXpresso IDE. The changes to be made in the source code were not many because the application was not very complex either, it only needed one UART and a few GPIOs with interrupts.
Now I think it's too late to be able to buy a 32-bit microcontroller in quantity to market a product. Maybe some LPCs, but no Kinetis or NXP i.MX are in stock. I bought the RT1064 and STM32H747 in quantity when the crisis began, and thus I was able to get enough to be able to work, but now it is impossible, there is nothing in stock.