You can't change the engine for the table to one which doesn't support foreign keys without removing the foreign key constraints.
Documentation for the MEMORY engine
If the new engine doesn't support them, they simply can't exist, so you need to remove them before making the appropriate changes.