US stocks end lower following court ruling throwing Trump tariffs into doubt