Accounts of it are all over the web, but I’ll try to give you the short story here.
In oral discussions from the bench prior to arguments for Santa Clara County v. Southern Pacific Railroad (1886; a dispute over corporate taxation), Chief Justice Morrison Waite said something (obiter dictum — “said in passing”) to the following effect:
…the Fourteenth Amendment to the Constitution, which forbids a State to deny to any person within its jurisdiction the equal protection of the laws, applies to these corporations.
The court reporter including this statement in the “headnote” to the case entry in the United States Reports — the record of Supreme Court decisions.
That court reporter was J.C. Bancroft Davis, former president of the Newburgh and New York Railway Company.
Davis checked with the chief justice before including the passage. The justice did not demur, though he did acknowledge:
we avoided meeting the constitutional question in the decision
So the passage — in the headnote, not the decision itself — had no force of law, no value as precedent.
But it has been repeatedly cited as precedent, starting with Associate Justice Stephen J. Field’s citation three years later in Minneapolis & St. Louis Railway Company v. Beckwith.
Corporations are persons within the meaning of the clauses in the Fourteenth Amendment to the Constitution concerning the deprivation of property, and concerning the equal protection of the laws. Santa Clara County v. Southern Pacific Railroad, 118 U. S. 394, and Pembina Mining Co. v. Pennsylvania, 125 U. S. 181, followed.
Field was there for Santa Clara, so he knew it held no precedent value, but he cited it anyway, as if it did. For the grimy details of Field’s conflicts of interest, I’ll direct you here.