Will an internal defibrillator keep on shocking the heart when the patient dies?

No. Most defibrillators will stop after 10-15 shocks. Also, death occurs from asystole so a defibrillator would eventually sense that and try to pace but not shock.
It will try until .. It will keep trying for a while until its battery is exhausted or until somebody programs it to stop.