Jeff Reifman sez, "In light of this week's ruling that for-profit corporations should have protection for their religious beliefs, I thought I'd summarize the timeline of Supreme Court decisions that established corporate constitutional rights US law." tl;dr: most of it comes from the anti-slavery 14th Amendment.
While the word corporation doesn't appear in the Constitution, the Supreme Court has now granted corporations commerce and contracts clause protections, personhood, due process, protection from double jeopardy and unreasonable search and seizure and free speech rights.
Almost all of these rights originate from the twisting of the Fourteenth Amendment's equal protection clause which was meant to provide rights for freed slaves.
While not called out in my summary specifically, the formal right of corporations to screw Americans was established with 2003's Lawrence v. Texas, in which the Court struck down laws against sodomy.
The History of Corporate Constitutional Rights
(Thanks, Jeff!)