The case of Sgt. Bowe Bergdahl, an American soldier who, after leaving his post, was held hostage by the Taliban for five years, became a recurring theme of Donald Trump’s unruly campaign speeches.

In August 2015, Mr. Trump fired up a New Hampshire crowd by calling Sergeant Bergdahl “a dirty rotten traitor.” He proceeded to falsely claim that “six young beautiful people were killed trying to find him.” Then he dismissed arguments that the former hostage’s “psychological problems” may have led him to walk off a base in Afghanistan in 2009. “In the old days,” Mr. Trump said, pantomiming an execution by pretending to fire a rifle twice. “Bing bong.”

Those remarks are certain to loom large over Sergeant Bergdahl’s court-martial, which is scheduled to start in April. Sergeant Bergdahl is charged with desertion and misbehavior in front of the enemy; a guilty verdict could result in a sentence anywhere from no jail time to life. But how can he get a fair trial in the military justice system when the next commander in chief has proclaimed his guilt and accused him of treason?

The short answer is he can’t. Eugene Fidell, Mr. Bergdahl’s lawyer, says he intends to submit a motion the day Mr. Trump takes office, cataloging the roughly 40 times Mr. Trump made disparaging remarks about his client, and seeking to have the case dismissed.