STM32F103 ARM - Modifying Clock At Runtime - FLASH Latency
Is setting flash latency optional? since in my case it worked even without it.


No. If you do not set the flash latency correctly, your program may sometimes read incorrect data from flash memory.


  When exactly do you call the FLASH_SetLatency function with the new wait state? Before setting the new clock or right after?


Before increasing the system clock frequency, or after decreasing it.

Having the latency too high for the system clock is mostly harmless -- it will slow the system down slightly, but that's it -- but having the latency set too low may cause malfunctions.