The announcements on Monday and Tuesday appeared to be more about political messaging than practical action. Stung by a backlash from his conservative supporters over his embrace of a trillion-dollar-plus spending measure that did not fund his promised border wall, and lacking a legislative initiative to champion with the approach of midterm congressional elections this fall, Mr. Trump has reverted to the aggressive anti-immigration messaging that powered his presidential campaign and has defined his first year in office.

Immigration advocates denounced Mr. Trump’s announcement as a political ploy.

“He cannot get funding for his wall, so instead he irresponsibly misuses our military to save face,” Kevin Appleby, the senior director of international migration policy at the Center for Migration Studies of New York.

Others said Mr. Trump’s sudden declaration was merely an instance of a now-familiar pattern wherein the president reacts angrily to something he sees in the news — in this case, reports of a large group of migrants from Honduras traveling through Mexico with hopes of reaching the United States — and seeks to use it as a cudgel against his political opponents.

“Some of it is just the guy at the end of the bar yelling his opinions — his gut reaction is to say we’ve got to send the military,” said Mark Krikorian, the executive director of the Center for Immigration Studies, which advocates slashing immigration levels. “But there may also be an element here of political messaging — and a desire to create problems in November for Democratic candidates who have refused to embrace his policies.”

Whatever Mr. Trump’s motivation, the president floated the idea after days of public stewing about the potential for the group of Honduran migrants to pour into the United States.

“We have very bad laws for our border, and we are going to be doing some things — I’ve been speaking with General Mattis — we’re going to be doing things militarily,” Mr. Trump said Tuesday morning, seated beside the defense secretary at the meeting with Baltic presidents. “Until we can have a wall and proper security, we’re going to be guarding our border with the military. That’s a big step. We really haven’t done that before, or certainly not very much before.”