In some of my flights, I see the crew spray the cabin with some sort of insecticide after making an announcement which says that it's not harmful.
Why do they spray that in some flights and not the others? and is it really not dangerous to health?
Some countries require that in-bound flights to be disinfected (either flights arriving from all countries or certain countries that are known to be affected with certain diseases, such as Malaria). A couple of mosquitoes or other insects can reproduce in the destination country and over time they will cause a general health or agriculture problem.
Even in flights where you do not see the crew spraying the insecticide, there is a big chance that the cabin was sprayed with a residual insecticide before the passengers board. The cargo hold will also be sprayed as it is pressurized and living things can survive there during the flight.
Is it dangerous? no, it is harmless. Some people might have light reactions, but this is quite rare. I have personally never seen or heard of anyone complaining about it.