Uganda is a target of al Shabaab because it has deployed thousands of peacekeeping troops to Somalia. Political analysts say the peacekeepers are effectively all that prevents the militants from overthrowing Somalia's Western-backed government.
Uganda also fears possible strikes by the al Qaeda-affiliated rebels wanting to avenge the killing of Osama bin Laden by U.S. special forces.
Police detained the men on Friday when they failed to produce any identity documents, refused to give their names and said they had come from Somalia via Sudan after their bus was stopped at a roadside checkpoint 450 km northwest of Kampala.
"When a group of young Somalis like these enter the country in a very suspicious manner, it's possible they could be coming to execute al Shabaab's threats," Samuel Okot, Uganda's northwest regional police commander told Reuters on Monday.
"We don't want to take chances."
Al Shabaab claimed responsibility for a twin bomb blast in the Ugandan capital, Kampala, last July that killed 79 people.
It was not immediately clear how the men had earlier crossed into Uganda without any documents. Police are now interrogating them in Kampala, Okot said.
Over the weekend, al Shabaab reiterated accusations that Ugandan peacekeepers were committing "heinous crimes" in Somalia, threatening more strikes on Ugandans.
"It is you, the people of Uganda, who will pay the heftiest price for your army's invasion of our country," al Shabaab said in a written statement on May 14, two days after Uganda's President Yoweri Museveni was sworn in for a fourth term.
"And now that you have made your choice very clear by re-electing Museveni, it is time for you to bear the burden of your choices."
Uganda's role in Somalia has won Museveni support from foreign powers reluctant to put their own boots on the ground, mindful of an intervention by the United States in Somalia in the early 1990s considered a disaster at home.
Museveni, who has been in power for 25 years, says withdrawing the peacekeepers would threaten regional security. Intelligence services in Uganda and Kenya say they have foiled a number of planned attacks since