when you send current through the motor, because of the high inductance (created by the coil shape of the winding combined with the iron in the stator, which forms an elecromagnet) it takes extra time to reach a given amount of current, compared to the time it would take if you used a straight wire with no iron stator.
during this “extra time” you are building a magnetic field or “compressing a spring” or “storing energy”… when you remove the battery voltage, the spring releases and powers the current that continues to flow for a short time without any battery voltage.