http://www.phrases.org.uk/meanings/139650.html
Basically comes from animals having rabies, and turning a bit crazy. When you are supposedly 'foaming at the mouth' you are quite enraged. The link gives a much better answer than I'm able to provide.
it depends on how and why you die. i have seen foam come out when dying
When dogs get angry foam come to their mouths
Rabies? and if they die from ingesting chlorine
Foam WillAnd rabies!
The foam occurs when the victim was attempting to breathe in the water. The violent gasping for breath mixes water and air enough to cause froth that builds up in the lungs and trachea, eventually leaking out the mouth.
Hogs will foam at the mouth when they are overheated. This is also a sign of rabies, however, this is a rare condition in pigs.
Rabies
dope
Yes it can. My mother has just died from a sudden heart attack which caused her to foam at the mouth.
To scare of animals
Apparently it can. My mother has just had a stroke, and woke up from her lunchtime nap with a mouth full of foam, unable to swallow.
Yes, a young horse may foam at the mouth when losing caps (baby teeth) and getting in new teeth. The process that creates the foam results from excess saliva and a horse that works his mouth and the saliva.