Hello,
First, it would be important to mention that for the migration to be a drop-in replacement, you need that both MCUs are the same package.
Regarding the software, you cannot flash the firmware of the K64 into the K24. There are some changes between these two families that won't allow this to work. For starters, the frequency of the clocks. It's more common for customers to migrate from the K20 family to the K60. In your case that you will do the opposite, you have to pay attention to the peripherals that your application is currently using. This is because the K60 family has more peripherals than the K20. Just to put an example, if your application right now is using Ethernet, it won't be possible to migrate to the K20 due to the lack of Ethernet on this family.
Regards,
Victor