While the United States has planted an American flag on the moon during the Apollo 11 mission in 1969, it was a symbolic gesture and not a formal act of claiming lunar territory.
The Outer Space Treaty of 1967, which has been ratified by over 100 countries, explicitly states that outer space, including the Moon, is not subject to national appropriation by claim of sovereignty, by means of use or occupation, or by any other means.
Therefore, placing a flag on the moon doesn't grant any country ownership or control over it.