If I remember correctly, exiting a FOR NEXT loop early leaves a pointer on the stack. Doing it too many times will fill the stack completely causing your problem. Any leftover pointers reduces the stack size.
Back in the day or at least for the C-64, the way to clear the FOR NEXT loop for an early exit is to set the FOR variable to the max value of the loop before exiting.
Line 40 should be changed to this:
40 IF <conditional> THEN J=20 : GOTO60
A better option for BASIC Engine is to use a DO LOOP and exit when the <condition> or the max value occurs.