NEW YORK—Ross Ulbricht, who is accused of running the secret online drug marketplace Silk Road, has a crucial decision in front of him.

U.S. District Judge Katherine Forrest told the 30-year-old late last week that he had until the government rests its case Monday to decide whether to testify in his own defense.

The move, which raised questions among some legal experts, highlights how the decision to testify is one of the toughest to make in a criminal trial.

Mr. Ulbricht faces the possibility of life in prison if convicted of criminal charges related to Silk Road, an underground website that sold illegal drugs and allegedly reaped him millions of dollars in commission, according to prosecutors.

Judge Forrest’s ultimatum is an unusual move, some legal experts said, as defendants are typically allowed to wait until the end of a trial before deciding whether to testify. In a heated exchange with the judge on Thursday, Mr. Ulbricht’s lawyer, Joshua Dratel, objected to the timing.