"The defendant horribly fired at passengers on a crowded subway train, interrupting their morning commute in a way this city hasn't seen in over 20 years," Assistant U.S. Attorney Sarah Vinick said in a statement.
The court ordered that James be placed in a Brooklyn detention center and a psychiatric examination be conducted.
Earlier it became known that 16 people were injured as a result of the shooting.
A US court later charged James with a terrorist attack.