The prefix code is a numbered code individually assigned to each Federation starship. It is a defensive measure designed to help Starfleet personnel combat enemies who have seized control of a ship of their fleet, and to prevent enemy ships from attempting to seize control of a Starfleet vessel.
When the relevant code is entered into the computer system of another ship, that ship is able to remotely control systems on the other ship. This includes weapons and defense systems, which enables the controlling ship to reduce the seized ship's fighting capabilities in order to permit effective attacks. However, a knowledgeable enemy can take the precaution of changing the code.
This defensive feature proved a real lifesaver in the initial engagement of the Battle of the Mutara Nebula where the damaged USS Enterprise managed to drive off the USS Reliant by accessing its five-digit code, 16309 and using it to lower the Reliant's shields, allowing the few remaining phaser blasts to cause fairly moderate damage. Without the prefix code, Admiral Kirk would have been completely out of options and very likely would have been forced to surrender and perhaps have the Enterprise destroyed by the vengeful Khan. (Star Trek II: The Wrath of Khan).
In 2367, Captain Jean-Luc Picard revealed the prefix code of the USS Phoenix to Cardassian authorities when its captain, Benjamin Maxwell, waged war on the Cardassians. The code allowed a Cardassian warship to remotely disable the Phoenix's shields. Unfortunately, the Phoenix was still able to destroy the warship. (TNG: "The Wounded")