Military occupation
Occupation and the laws of war: A dominant principle that guided combatants through much of history was "to the victory belong the spoils". Emer de Vattel, in The Law of Nations (1758), presented an early codification of the distinction between annexation of territory and military occupation, the latter being regarded as temporary, due to the natural right of states to their "continued existence". According to Eyal Benvenisti's The International Law of Occupation, Second Edition (2012), "The foundation upon which the entire [modern] law of occupation is based is the principle of inalienability of sovereignty through unilateral action of a foreign power, [and from this principle] springs the basic structural constraints that international law imposes upon the occupant."
The Hague Convention of 1907 codified these customary laws, specifically within "Laws and Customs of War on Land" (Hague IV); October 18, 1907: "Section III Military Authority over the territory of the hostile State". The first two articles of that section state:

Art. 42. 
Territory is considered occupied when it is actually placed under the authority of the hostile army. 
The occupation extends only to the territory where such authority has been established and can be exercised.

Art. 43. 
The authority of the legitimate power having in fact passed into the hands of the occupant, the latter shall take all the measures in his power to restore, and ensure, as far as possible, public order and safety, while respecting, unless absolutely prevented, the laws in force in the country.

In 1949 these laws governing the occupation of an enemy state's territory were further extended by the adoption of the Fourth Geneva Convention (GCIV). Much of GCIV is relevant to protected civilians in occupied territories and Section III: Occupied territories is a specific section covering the issue. Under GCIV, protected civilians in general are:

those "who ... find themselves ... in the hands of a Party to the conflict or Occupying Power of which they are not nationals". This generally refers to civilians of an enemy state, including refugees, and stateless persons.
neutral citizens in occupied territory regardless of diplomatic status
refugees of the occupying power prior to hostilities who cannot be arrested, prosecuted, or deported from occupied territory except for crimes committed after the conflict or beforehand which are also crimes under the law of the occupied state that would permit peacetime extradition as defined under Article 70
Nationals of an enemy state not a signatory or acceded to GCIV are not protected by it. Neutral citizens who are in the home territory of a belligerent nation if their country of origin has diplomatic ties or elsewhere outside occupied territory are not protected. Nationals of a co-belligerent (allied) state which holds diplomatic ties with a belligerent nation are excluded from protection in both locations.
On whether the definition of military occupation applies to anywhere else, the 2023 United States Department of Defense (DOD)'s Law of War Manual states "the law of belligerent occupation generally does not apply to (1) mere invasion; (2) liberation of friendly territory; (3) non-international armed conflict; or (4) post-war situations (except for certain provisions of the GC [IV])." The DOD's statement is consistent with the definitions provided by Article 42 of the 1907 Fourth Hague Convention and Article 4 of the Fourth Geneva Convention.
Article 6 of GCIV restricts the length of time that most of the convention applies:

The present Convention shall apply from the outset of any conflict or occupation mentioned in Article 2.
In the territory of Parties to the conflict, the application of the present Convention shall cease on the general close of military operations.
In the case of occupied territory, the application of the present Convention shall cease one year after the general close of military operations; however, the Occupying Power shall be bound, for the duration of the occupation, to the extent that such Power exercises the functions of government in such territory, by the provisions of the following Articles of the present Convention: 1 to 12, 27, 29 to 34, 47, 49, 51, 52, 53, 59, 61 to 77, 143.

GCIV emphasised an important change in international law. The United Nations Charter (June 26, 1945) had prohibited war of aggression (See articles 1.1, 2.3, 2.4) and GCIV Article 47, the first paragraph in Section III: Occupied territories, restricted the territorial gains which could be made through war by stating:

Protected persons who are in occupied territory shall not be deprived, in any case or in any manner whatsoever, of the benefits of the present Convention by any change introduced, as the result of the occupation of a territory, into the institutions or government of the said territory, nor by any agreement concluded between the authorities of the occupied territories and the Occupying Power, nor by any annexation by the latter of the whole or part of the occupied territory.

Article 49 prohibits the forced mass movement of protected civilians out of or into occupied state's territory:

Individual or mass forcible transfers, as well as deportations of protected persons from occupied territory to the territory of the Occupying Power or to that of any other country, occupied or not, are prohibited, regardless of their motive. ... The Occupying Power shall not deport or transfer parts of its own civilian population into the territory it occupies.
Protocol I (1977): "Protocol Additional to the Geneva Conventions of 12 August 1949, and relating to the Protection of Victims of International Armed Conflicts" has additional articles which cover occupation but many countries including the U.S. are not signatory to this additional protocol.
In the situation of a territorial cession as the result of war, the specification of a "receiving country" in the peace treaty merely means that the country in question is authorized by the international community to establish civil government in the territory. The military government of the principal occupying power will continue past the point in time when the peace treaty comes into force, until it is legally supplanted.
"Military government continues until legally supplanted" is the rule, as stated in Military Government and Martial Law, by William E. Birkhimer, 3rd edition 1914.

Qualification of a territory as occupied: Article 42 under Section III of the 1907 Fourth Hague Convention specifies that a "[t]erritory is considered occupied when it is actually placed under the authority of the hostile army." This definition does not rely on a subjective perception, but rather on the "territory's de facto submission to the authority" of the occupant. Article 2 of the Geneva Conventions indicates that the definition applies to "all cases of partial or total occupation of the territory of a High Contracting party", even if no armed resistance is encountered. The form of administration by which an occupying power exercises government authority over occupied territory is called military government.
There does not have to be a formal announcement of the beginning of a military government, nor is there any requirement of a specific number of people to be in place, for an occupation to commence. Birkhimer writes:

No proclamation of part of the victorious commander is necessary to the lawful inauguration and enforcement of military government. That government results from the fact that the former sovereignty is ousted, and the opposing army now has control. Yet the issuing such proclamation is useful as publishing to all living in the district occupied those rules of conduct which will govern the conqueror in the exercise of his authority. Wellington, indeed, as previously mentioned, said that the commander is bound to lay down distinctly the rules according to which his will is to be carried out. But the laws of war do not imperatively require this, and in very many instances it is not done. When it is not, the mere fact that the country is militarily occupied by the enemy is deemed sufficient notification to all concerned that the regular has been supplanted by a military government. (p. 61)

Concept of effective control: The survey of the case-law regarding Article 42 of the 1907 Fourth Hague Convention reveals that the duration of effective control by the occupying power and its encounter with insurgents, terrorists or guerrillas that are able to exercise control over certain areas of the country are immaterial to the applicability of the law of occupation and do not alter the legal status of the occupied territory. For example, in 1948 the U.S. Military Tribunal in Nuremberg held that: In belligerent occupation the occupying power does not hold enemy territory by virtue of any legal right. On the contrary, it merely exercises a precarious and temporary actual control.

End of occupation and authority shift: According to Eyal Benvenisti, occupation can end in a number of ways, such as: "loss of effective control, namely when the occupant is no longer capable of exercising its authority; through the genuine consent of the sovereign (the ousted government or an indigenous one) by the signing of a peace agreement; or by transferring authority to an indigenous government endorsed by the occupied population through referendum and which has received international recognition".