He described it as "unnecessary and wrong and must not be used again".
It follows media reports alleging that several people suspected to be connected to the murder of a senior police officer had been tortured.
Ugandan security officials have been accused by human rights groups of using torture to get confessions.
Mr Museveni said torture was wrong because it was sometimes employed on innocent people, which was unfair, and could lead them to admitting guilt to stop the pain.
He also said that good investigators could obtain convictions without using torture.
Assistant Inspector General of Police Andrew Felix Kaweesi, the third most senior police officer in the country, was shot dead outside his house in March.
Ugandan newspapers have shown suspects charged in the murder of Mr Kaweesi with visible signs of injuries when they appeared in court.
On Sunday, Maria Burnett from Human Rights Watch (HRW) called for police to take suspects' allegations of torture seriously. She also said the officers allegedly involved should be investigated "for torture and mistreatment".
She added that HRW has spoken to hundreds of witnesses over the last 15 years who have complained of being tortured.
Uganda ratified the United Nations Convention against Torture in 1986, which means that torture should be outlawed in the country.
Uganda's President Yoweri Museveni has written a letter to his top security chiefs warning against the use of torture.