A New York appeals court ruled on Thursday that new congressional districts drawn by Democrats violated the state’s ban on partisan gerrymandering, partially upholding a lower-court ruling that would block the state from using the lines in this year’s critical midterm elections.