The batter is put out because an outfielder (or an infielder running in the outfield, or foul territory) catches the ball on the fly (alternatively if the batter would have been out if not for an error or if the outfielder drops the ball and another runner is put out).