Loyalty oaths in the US were initiated during the 1950s and 1960s. During the 1950s during Soviet annexation of eastern European Nations and developing a Nuclear Threat.
Senator Joseph McCarthy swayed the Nations thoughts to concern about communist spies, agents and saboteurs and a fear agents may injure the U.S. government through espionage or violence.
They were basically to secure the loyalty and well being of American citizens.