This was highly illegal and frowned upon in polite society, but doctors needed the body parts to study anatomy and paid for them.
By chance I've recently read Dicken's "A Tale of Two Cities", which uses the banker's messenger secretly moonlighting as such a resurrectionist digging up bodies at night, as a plot device. Quite a fun read.
And in addition to the body snatching, we also had serial killers who flat out murdered people to sell their bodies to medical schools. See, Burke and Hare.
Were they actually stealing bodies? Was that something official or done in secret?