Please explain the legal mechanics of how this happened, with special attention to the "spoils of war" doctrine.
Easy: In unconditional surrender the victors get to set the rules, and rearrange political boundaries as they see fit. It has ALWAYS been that way. Just look at the “realignment” after WWII: Entire empires disappeared.