Here's what appears to happen. A spell is 'queued' for the pet to cast (stores the target, spell, spell line). The target dies before the spell is casted giving you the 'You must select a target for this spell'. Now, under normal circumstances the spell will be removed from the queue (and it works 99% of the time). However, due to some strange circumstances (possibly lag?) the spell is not removed from the queue. In fact it appears to become 'stuck' in the queue which then creates a stack loop. Basically the error is this:
A calls B calls C calls A calls B calls C calls A and so on until the computer says ENOUGH! and completely kills the executable. So, the loop goes like:
CastSpell calls Notify calls CheckQueue calls CastSpell calls Notify calls CheckQueue.
Like I said, under normal circumstances that works because if nothing is in the queue, CheckQueue doesn't reach CastSpell... But if there is a pesky little spell that gets stuck in the queue... You can see where this is going

.