Arbitration is legal because of the Federal Arbitration Act of 1925. Before that, judges in the United States treated arbitration clauses as unenforceable despite freedom of contract. [1] It’s a bit odd that 80 years or so passed before consumer arbitration clauses suddenly became ubiquitous in the last decade, but nevertheless Congress could easily amend the law if it wanted to.
[1] https://scholarlycommons.law.case.edu/cgi/viewcontent.cgi?ar...