STM32F4 clock behaves very strangely
I've also seen strange things happen with MCU clock in STM32F1 and STM32F4 series but only in high count pin configurations like LQFP144 and more.
It is likely that your external crystal becomes unstable for some reason and the MCU automatically switches to internal clock. Check the 8MHz crystal pins on oscilloscope to be sure.
Try switching to internal oscillator if you dont need much accuracy in your main clock.