The gunman who shot and killed 10 people in a racially motivated attack in Buffalo, New York, has pleaded guilty to murder and terrorism charges.