Last year, Trump administration officials had floated the idea of transporting migrants to sanctuary cities, which do not strictly adhere to federal immigration laws, as a way to address the influx of migrants crossing the border with Mexico.

One of the highest-profile sanctuary cities is San Francisco, home to Speaker Nancy Pelosi, who is one of the president’s top political rivals and a thorn in his efforts to change American immigration laws. The White House raised the proposal again in February, suggesting it could punish Democrats for rejecting budget requests for border security.

Ms. Pelosi’s office condemned the Trump administration for the idea, which the Department of Homeland Security said on Thursday was ultimately rejected.

But Mr. Trump’s tweets on Friday indicated it was not off the table, and the president appeared to revel in the Democratic outrage, saying, “The Radical Left always seems to have an Open Borders, Open Arms policy – so this should make them very happy!”

Senator Edward J. Markey, Democrat of Massachusetts, a state with several sanctuary cities, criticized the president’s proposal.

“Trump’s plan to release migrants into ‘enemy’ cities as if they are some kind of contagion is reprehensible,” Mr. Markey tweeted. “Trump is obsessed with the border and sanctuary cities because he only wins by dividing people.”

There has been an influx of migrant families crossing the southern border into the United States, exceeding the staffing and resources available for immigration enforcement. And with a shortage of space in shelters and detention centers, immigration officials have been releasing migrants into the country as they wait to appear before an immigration court. Those courts are so backlogged with cases that it can be months or years before the migrants are called to appear before a judge.