Doctors, researchers, and law enforcement officers use autopsies to find out specific causes of death. If someone dies unexpectedly, the pathologist, or doctor who does the autopsy, can very often find out why or how the death happened.
In cases of accidents, homicides, suicides, and suspicious deaths, autopsies are almost always required by law. Autopsies are not often done following death from a terminal illness.
An autopsy can be requested of the death seems to be unusual for the type of illness the patient had or if there was a particular reason a doctor may want to investigate further. As well, sometimes autopsies are done for educational reasons, to help researchers further understand how a particular disease progresses.