Definition
This idiom refers to the state of being imprisoned indefinitely, with release contingent upon an official determination that it is safe to do so.
He was held in prison at His Majesty's pleasure, indefinitely, pending further notice.
The offender was imprisoned at Her Majesty's pleasure, meaning he would be detained until the authorities deemed it safe to release him.
She was sentenced to be detained at His Majesty's pleasure for several serious offenses, with no specified release date.