score:13
Oops! You changed the title of the question.
I originally answered that according to the original title of your question that never happened.
To answer the title of your question, never.
The phrase "The U.S. was occupied by foreign troops" means that the entire United States of America was occupied by foreign troops, not that some tiny part of the USA was occupied by foreign troops. Since the official independence of the USA in 1783 there has never been a single moment when the entire USA was occupied by foreign troops.
But I also answered the text of your question:
But if "when was the most recent time that a foreign power had military occupancy on the U.S.'s soil/waters?" asks about foreign military occupation of parts, however large or small, of the USA instead of the entire USA then there have been several times in history when that has happened.
I think that the latest time there has been any foreign military occupation of any part of the USA would have been during World War Two in 1941-1945, when Japan occupied for varying lengths of time several regions that were part of the USA.
For example, Japan invaded the Philippines on 8 December 1941 a few hours after the attack on Pearl Harbor and completed the conquest on 6 May 1942. The US lead invasion force landed in the Philippines on 20 October 1944 and fighting continued until the Japanese surrender on 2 September 1945. So if the Philippines are considered to be "U.S.'s soil/waters" 2 September 1945 would be the answer.
https://en.wikipedia.org/wiki/Japanese_occupation_of_the_Philippines1
Japanese forces invaded and occupied Attu and Kiska, two of the Aleutian Islands in the Territory, and later State, of Alaska on Junes 3, 1942, and the last Japanese troops didn't retreat from Kiska until July 29, 1943.
https://en.wikipedia.org/wiki/Aleutian_Islands_Campaign2
So the last time that any part of the USA was occupied by foreign troops would probably be either 29 July 1943 or 2 September 1945, depending on whether the Philippine Islands are considered to be part of the USA during 1941-1945.