The prefix code was a numbered code individually assigned to each Federation starship. It was a defensive measure designed to help Starfleet personnel combat enemies who had 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 was entered into the computer system of another ship, that ship was able to remotely control systems on the other ship. This included weapons and defense systems, which enabled the controlling ship to reduce the seized ship's fighting capabilities in order to permit effective attacks. However, a knowledgeable enemy could 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, during which 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 James T. 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 Noonien Singh. (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")
In 3189, the engineering team aboard the USS Discovery had the prefix codes to the onboard sensors of the KSF Khi'eth. Using these codes, the team hoped to gain back door access to the systems of the Khi'eth so they could see inside the ship and the activities, if any, happening there. (DIS: "Terra Firma, Part 1")
In the CD-ROM game Star Trek: 25th Anniversary, the USS Enterprise used the prefix code of a hijacked Ptolemy-class tug to lower its shields and beam a landing party aboard. In the book The Autobiography of James T. Kirk, Kirk notes that Garth of Izar took remote control of his enemy's weapons console in the Battle of Axanar, leading to the implementation of the prefix code on Federation ships to prevent the same tactic from being used against them.
In the comic book miniseries Star Trek: The Q Conflict, when the four crews are "shuffled" to compete against each other as part of a wager between Q, Trelane, the Organians, and the Metrons, Commander William T. Riker (temporarily "reassigned" to Captain Kathryn Janeway's team) is able to help his team gain an advantage by using his knowledge of the prefix codes of the Enterprise-E's shuttles to disable the shuttle being used by Captain Jean-Luc Picard's team for the first round of the contest, causing Picard's shuttle to make a forced landing some distance from their target.