From Hidden Frontier
A Counselor is a position aboard Starfleet vessels and installations, normally held by a Starfleet officer with training in psychology. They are responsible for the mental well-being of the crew and civilian staff. Depending on the role of the vessel or installation, the position may also have a diplomatic role, helping advise in first contact and other situations.
Much like the Chief Medical Officer, a ship's Counselor can relieve other officers and crew members of duty if he or she feels that they are suffering from a condition that hinders their ability to perform their duties effectively. Counselor Elbrey relieved Rear Admiral Knapp of his command of the allied fleet during the Battle of Tren'La when it was discovered that Siroc was holding his daughter, Traya, as a hostage which caused him to order a halt to the advance of his forces in battle at a critical juncture. (HF 6.06 - "Her Battle Lanterns Lit")
At a Captain's discretion, a ship's Counselor may be allowed to wear something other than their normal Starfleet uniform while on duty.