In the main LED and CFL flash because some thing allows a little energy to reach the bulb, which is more than the leak resistor can disperse.
This is normally capacitive or inductive linking, very common with two way switching where the long cable runs allow more AC to transfer. But also happens where electronic switches are used which need a small amount of energy to work.
The fix is normally to fit a load capacitor
View attachment 266010 These allow more current to flow before the voltage raises to point where the lamp will flash.
However the connection to a fan is unlikely to cause the problem, in fact the reverse, the load from the fan is likely to stop a light which was flashing not start one flashing.
Hence asking for pictures of the connection in the ceiling rose. It seems very likely a black or blue wire was not neutral but a line feed, or some other fault. Does the fan work when it should work? i.e. when the light is on?