Historically, consent was not a factor at all in how cadavers were acquired for medical use. The bodies of executed criminals were once used for medical examination. These practices later gave way to simply stealing corpses. There weren't laws against removing a dead body from the grave at the time, so it was common for medical students to spend nights digging up cadavers for scientific practice. While this practice eventually became illegal, it continued to be common long after laws were passed.
Today, it is illegal for medical institutions to buy bodies. This is to curb the use of bodies without consent. Instead, they must be donated by willing individuals who make arrangements for the donation of their body when they die.