Error code B504 occurs because the print head does not detect any ink and printer stop printing to protect the print head. The print head need to heat up and spits out the ink on to the paper, if no ink supply to print head and the printer has a chance of burning out the print head if it continue to print.
Once an error occurs, the printer stops working and you can not remove the ink cartridge. You can try to hard resetting (power off the printer and unplug for 5 seconds ) the printer. If the error disappear, you can remove the ink cartridge normally, check the condition of the ink cartridge and replace the ink cartridge with a new once.
If the hard reset still doesn't work, you may need to remove the ink cartridge manually, find the video below on manually removing the ink cartridge.