In 1940 Russell was appointed to teach logic and mathematics at the City College of New York. A taxpayer brought suit to have the appointment revoked on the grounds that his published views on marriage and sexual morality made him unfit, and in March 1940 a New York state judge annulled the appointment, describing the chair as one of indecency and characterising Russell's work as lecherous, libidinous and narrow-minded. The city declined to appeal. Russell was left without the post and, with wartime travel restricted, without much means of earning.
Two details are usually omitted. The judgement concerned his writings on sex, not his atheism, and he was never permitted to be a party to the case or to answer it in court, he was the subject of the proceedings rather than a defendant in them. John Dewey and others organised in his defence and lost.
He had drawn the distinction he is quoted for well before this: that he would call himself an agnostic among philosophers, because he could not prove there is no God any more than he could prove there is no Homeric Olympus, and an atheist in ordinary company, because in practice he regarded the Christian God as no more probable than the Olympian ones. It is a distinction about audience rather than about the state of his belief, and it is regularly quoted as though it were only the first half.