A soldier who was shown wearing his uniform at a protest in Baltimore, Maryland, last week was "not actively participating" but a victim of "bad timing," officials said.

"The soldier is part of the Maryland National Guard. He was not actively participating in the protest, but his image was captured as he walked home from work near the location where some of the recent anti-police/"Black Lives Matter"/Freddie Gray protests have taken place," according to a statement posted on the 15th Sustainment Brigade Facebook page.

The soldier in the photo was wearing the brigade's patch on his right sleeve, and the brigade received numerous messages on its Facebook page after the photo was posted on several military or veterans Facebook sites.

The photo, which was taken from a local Baltimore television news report, was posted on sites such as U.S. Army W.T.F.! Moments, according to the statement from the 15th Sustainment Brigade

Many social media users quickly blasted the soldier for participating in the protest while in uniform, with some calling for him to be punished via court-martial.

Col. Charles Kohler, a spokesman for the Maryland Guard, confirmed to Army Times that the soldier works at Cade Armory, which is very close to where the protests were taking place this week.

"Every indication is that he is a solid soldier. He knows, and so does his chain of command, it was a case of bad timing," he said. "He was walking home from work and saw the demonstration and stopped as they walked by, and then someone took his picture."

Up to 2,000 Maryland Guard soldiers and airmen were expected to arrive in Baltimore by evening on April 28 in response to riots and violence in the city April 27Monday night.

Rioters torched a pharmacy, set police cars on fire and threw bricks at police officers hours after thousands mourned Freddie Gray, who died from a severe spinal injury he suffered while in police custody.

Monday's riot was the latest flare-up over the mysterious death of Gray, whose fatal encounter with officers came amid the national debate over police use of force, especially when black suspects are involved. Gray was African-American. Police have declined to specify the races of the six officers involved in his arrest, all of whom have been suspended with pay while they are under investigation.

Maryland Gov. Larry Hogan declared a state of emergency and called in the National Guard to help restore order. Authorities also have put in place a weeklong, daily curfew beginning Tuesday April 28 from 10 p.m. to 5 a.m.

The Guard will be in place for "as long as it takes," said Rick Breitenfeldt, a spokesman for the National Guard Bureau.

The troops, who are mostly military police soldiers plus a handful of airmen, will provide security, conduct presence patrols and support infrastructure security, Breitenfeldt said.

Plans currently call for about 2,000 Guard troops to support authorities in Baltimore, but the Maryland Guard has up to 5,000 troops available to respond if needed, he said.