In 1943 the United States was totally immersed in World War II so that was a pretty gutsy call by the SCOTUS.
The Pledge, until 1954 read "… and to the republic for which it stands, one nation, indivisible with liberty and justice for all."
In that year the words "under God" were added at the urging of President Eisenhower who said,
"In this way we are reaffirming the transcendence of religious faith in America's heritage and future; in this way we shall constantly strengthen those spiritual weapons which forever will be our country's most powerful resource in peace and war."
Eisenhower, not noted as having worn his religion on his sleeve, was still President in 1956 when the official motto was determined to be "In God We Trust."
As the media wrings its hands over the intrusion of religion in politics and government, it is useful to remember that in America, it has always been thus.