This thread has some of wrong assumptions about how the bootloader works. Maybe that's harmless, or maybe it's leading to wrong conclusions? So here's a quick attempt to clear up a few. Not sure if this will really help, but seems worthwhile to spend a little time writing...
The bootloader is implemented in a separate small microcontroller. So it's not like a traditional bootloader which can't do anything while not actually executing on the main processor. While your program runs, it sits there doing very little, but not absolutely nothing. There are 2 ways you can get into bootloader mode. One is the press the pushbutton. The other is with a specific breakpoint instruction (which you can find buried inside the USB code). When you click Upload in Arduino, a program on your PC tries to find the USB device of your Teensy and send it a request to reboot. If your code is still running properly, it will hear that request and execute the breakpoint instruction to get the bootloader chip's attention. So while your program is running, the bootloader chip is watching to check whether the main processor has gone into a special halt mode because of that instruction. The 7 or 9 blink you're seeing are (probably) because it wasn't able to access the JTAG port in the ways it needs to observe the processor's state. Generally those more-than-4 blink errors happen only while your program is running. Even when programs "crash", usually JTAG can observe the CPU state. Not many things really interfere with the JTAG, but one thing that absolutely does is rebooting the main processor. On many chips the JTAG still works even while the process is in reset, but these IMXRT chips have a variety of security measures which normally only come into play with secure mode, but JTAG access definitely stops while the process in reset and for some time after it starts up. Whether your code is somehow triggering a reboot, I don't know. It's almost impossible to say from only the available info. So instead, I'm just trying to clear up some possible misunderstanding, in hope that might help.