Duncan Ondimu argued against granting bail to the two Iranians, saying they had filmed restricted government sites. Sayed Nasrollah Ebrahim and Abdolhosein Gholi Safaee were arrested last week in an Iranian diplomatic car in the capital, Nairobi. They have denied the charges.
Iran says the men are lawyers and were in Kenya representing two other Iranians jailed for 15 years for terrorism.
According to the Iranian Embassy, the men committed no offense in taking pictures of iconic buildings. "It is not surprising they took any of the photos of the buildings, they did so as would any other foreigner," the deputy ambassador said in a court document.
The men's Kenyan driver, Moses Keyah Mmboga, also faces a charge of abetting terrorism.
In June 2013, a Kenyan court convicted two Iranian nationals of plotting attacks against Western targets and sentenced them to life in prison. They led officials to a 15-kilogram (33-pound) stash of the explosive RDX. Their sentence was reduced on appeal in February to 15 years in prison.