Officers are employed under Royal Patronage; this is not subject to a lot of employment legislation. Although unusual, it is not unique to the Armed Forces. Judges are also employed under Royal Patronage.
The judiciary threatened a mass walkout if their pensions were messed with, and this seemed to work. Aahh, if only....