See? All nice and legal.
Not at all. From The Law of Land Warfare, Chapter 6, Occupation
358. Occupation Does Not Transfer SovereigntyBeing an incident of war, military occupation confers upon the invading force the means of exercising control for the period of occupation. It does not transfer the sovereignty to the occupant, but simply the authority or power to exercise some of the rights of sovereignty. The exercise of these rights results from the established power of the occupant and from the necessity of maintaining law and order, indispensable both to the inhabitants and to the occupying force.
It is therefore unlawful for a belligerent occupant to annex occupied territory or to create a new State therein while hostilities are still in progress. (See GC, art. 47; par. 365 herein.)
359. Oath of Allegiance Forbidden
It is forbidden to compel the inhabitants of occupied territory to swear allegiance to the hostile Power. (HR, art. 45.)