Relieved of Command is the method by which a commanding officer in Starfleet is relieved of his or her command of a starship or installation. It can be done on a voluntary or involuntary basis. A person can be relieved of command as punishment for violating the law or regulations, in which case a person is usually relieved of duty as well. A person can also be relieved of command simply because a superior officer has decided to take command, or they have command on an interim basis and the regular commanding officer has returned to his or her post.
A person is most often relieved of command by a superior officer. However, there are Starfleet regulations that provide for relieving a superior officer of command by a subordinate officer - such as the first officer or chief medical officer. These regulations are intended to remove a commanding officer who is endangering his or her command without good reason, has become physically or mentally disabled, or has otherwise violated the law or regulations. When upheld by Starfleet Command, such an action is not considered mutiny.
In 2246, on the USS Aldrin, Lieutenant Commander Christopher Pike discovered that Captain Kamnach was spoiling for a fight in the Vestian crisis. He discovered that Kamnach and weapons officer Hanley had altered logs and adjusted the power settings to the lasers. When Kamnach refused an order from Starfleet to return to post and inisisted on firing upon a Vestian ship, Pike relieved Kamnach of his command. A court martial cleared Pike of any wrongdoing, and Admiral Straczeskie revealed that he had assigned Pike to Aldrin because Starfleet had suspicions about Captain Kamnach. Straczeskie knew if Pike detected any wrongdoing by Kamnach that he would take action. (TOS novel: Burning Dreams)
Upon encountering the Planet Killer, first officer Spock decided not to attack the Planet Killer at that time. Commodore Matthew Decker insisted on an attack - and when Spock refused to do so Decker relieved Spock of command. Decker then carried out an attack which resulted in the USS Enterprise being seriously damaged. Once Kirk was able to establish communications with the Enterprise, he ordered Spock to relieve Decker of command. Decker asserted that Spock didn't have the authority to do so, but relented when Spock told him that he could file a formal protest if they survived to reach a Starbase, and when he realized that Spock was quite willing to have Decker arrested. (TOS episode: "The Doomsday Machine")
When Captain Jean-Luc Picard was possessed by an alien entity, he began acting in an increasingly strange manner. When Picard announced his intention to beam off the ship with the entity, Dr. Beverly Crusher relieved Picard of duty on the basis that he was mentally disabled. Overpowering the crew, Picard beamed off the ship, but was rescued by his crew when the alien entity wasn't able to continue with the captain. (TNG episode: "Lonely Among Us")
On the USS Voyager, in an alternate timeline created by the Kremin time weapon ship, the Doctor was once forced to relieve Captain Kathryn Janeway of her command. After Janeway was severly burned, the Doctor felt that she was becoming obsessed, and relieved her under medical regulations. As there was only a handful of people on Voyager, and the brig was offline, the Doctor was unable to enforce his decision. He did however note the fact in his log, and stated that Janeway was risking a court martial if they ever did make it back to Federation space. This timeline was erased when the Krenim temporal weapon ship was destroyed. (VOY episode: "Year of Hell", Part II)