Similar phrases have been in circulation since at least the 1700s including a similar passage in Voltaire's Candide: "But in this country it is good to kill an Admiral from time to time to encourage the others."
In 1863 the words of Voltaire were alluded to in a memoir by Lord William Pitt Lennox who described the hazing experienced by pupils at the Westminster School in England: "...of having a flogging, to encourage the others, as a Frenchman said of the execution of Admiral Byng."
The first known reference to the specific wording "...until morale improves" dates to a 1961 US Navy comic:
After that cartoon was published we see many different variations on the phase pop up such as, "The layoffs will continue until morale improves" from 1964.
The first reference to the specific phrase, "The beatings will continue until morale improves" is from a 1989 Usenet post on soc.culture.nordic:
Ohh yeah, definitely. I mentioned it in the context of perpetual layoffs. Almost every Friday, you’d have more people laid off because the company didn’t magically double its revenue since the previous Friday.
Beatings will continue until morale improves.