Freedom of contract has always been subject to current law. A contract to hire a hitman has never been legal. Neither was a contract to invade one of the royal monopolies that the English kings used to grant, nor a contract under which a judge would make a particular decision in return for a bribe.
"Freedom of contract" has never been "foundational" or "axiomatic" to the extent that a contract allowed a party to override a law, unless the law specifically allowed for that. (In some cases a law establishes a default rule for a situation, but reads something like: "unless the parties agree to the contrary".)
During the so-called "Lochner era" the US Supreme Court on multiple occasions "[struck] down economic regulations adopted by a State based on the Court's own notions of the most appropriate means for the State to implement its considered policies"{1)
The "era" was named for the case of Lochner v. New York, 198 U.S. 45 (1905) in which the Court struct down state law setting maximum working hours for bakers as a violation of "freedom of contract". The Court held that the law, which prohibited employing a baker or baker's assistant for more than 10 hours per day or 60 hours per week, was an:
unreasonable, unnecessary and arbitrary interference with the right and liberty of the individual to contract.
The Wikipedia article on the era (linked above) states that:
The beginning of the era is usually marked earlier, with the Court's decision in Allgeyer v. Louisiana (1897), and its end marked forty years later in the case of West Coast Hotel Co. v. Parrish (1937), which overturned an earlier Lochner-era decision.{2}
According to the Wikipedia article:
The Lochner era has been criticized from the left for judicial activism, routinely overturning the will of Congress, and also for the Court's failure to allow the political process to redress increasingly unequal distributions of wealth and power.{3}
Criticism among conservative scholars has focused on the use of substantive due process as a vehicle for protecting rights not explicitly mentioned in the Constitution.{4} Robert Bork called the Court's decision in Lochner v. New York an "abomination" that "lives in the law as a symbol, indeed the quintessence of judicial usurpation of power."{5}{6}
The axiomatic rule has long been that any contract is subject to current law, and that "freedom of contract" was limited by wherever valid current laws restricted contracts or their objects. The "Lochner era" in US law was an anomaly in this regard, and has been over for more than 80 years now.
This axiomatic rule in no way changed when anti-discrimination laws were passed (by the US Federal government, by most US states, by the UK, and by other jurisdictions). All that changed was what the current law prohibits. Leases, as with other contracts, must yield to any valid laws.
Notes
{1) Wikipedia article "Lochner Era" quoting, with slight modification Justice Bryer's dissent in SORRELL v. IMS HEALTH INC. ( No. 10-779 )
630 F. 3d 263 which was in turn quoting the dissent of then Justice Rehnquist in Central Hudson 447 U. S., at 589, in which Rehnquist said that a standard of Heightened Scrutiny would be a:
retur[n] to the bygone era of Lochner v. New York , 198 U. S. 45 (1905) , in which it was common practice for this Court to strike down economic regulations adopted by a State based on the Court’s own notions of the most appropriate means for the State to implement its considered policies.”
{2} quoting Jacobs, Harvey M. (2003). Private Property in the 21st Century: The Future of an American Ideal. Edward Elgar Publishing Ltd. p. 36. ISBN 978-1-84376-327-7. (page 47)
{3} Flagg, Barbara J. (1997). Was Blind, But Now I See: White Race Consciousness and the Law. New York: New York University Press. p. 75. ISBN 0814726437.
{4} Bernstein, David E. (November 2003). "Lochner's Legacy's Legacy". Texas Law Review. 82 (1)
{5} Bork, Robert H. (2003). "The Judge's Role in Law and Culture". Ave Maria Law Journal. 19 (21).
{6} Bork, Robert H (1990). The Tempting of America: The Political Seduction of the Law. Touchstone Books. p. 44. ISBN 978-0-671-73014-7.