The Supreme Court justices grappled with the legality of President Trump’s tariffs in an oral argument that stretched for almost three hours.