Yes, pirates can be detained and prosecuted even if they are not caught in the act of attacking a ship, especially if the pirate ships are found to have weapons such as guns, rocket-propelled grenades, modified ladders with hooked ends, or if they are holding hostages. Often times, pirate ships will have extra fuel and high powered engines on vessels disguised as fishing boats.
Prosecuting pirates however creates international challenges and can be difficult for many reasons. One very common reason is that navies are not necessary trained in evidence collecting and preservation techniques and many countries are willing to accept the costs of putting pirates in jail once they are found guilty