Why was Alan Turing vilified, convicted, and chemically castrated despite his vital contributions, while his near contemporary intellectual John Maynard Keynes, open about his homosexuality, was tolerated?
The British police did not actively pursue homosexuals qua homosexuals. There was hardly any secret about the widespread incidence of homosexuality at Oxbridge and the major public schools, and the police didn't see that as any of their concern. The recent editions of Chips Channons's diaries are filled with homosexual liaisons edited out of the earlier versions, and at no point did (or would) the police intervene.
And this is arguably not just a matter of the privileges of the upper classes: there are few cases of the police or courts expressing any particular interest in what happened behind closed doors, and convictions for sodomy were few and far between. Cases that did get to court usually involved children, or public exposure, or violence, or one of the parties feeling aggrieved and using the police in spite, or the implications of the then-current divorce laws. Otherwise, if you were not on the police's radar, how would they know what you were doing? They were not particularly interested in investigating the private activities of otherwise law-abiding people. The police did not, in general, regard rumour and gossip and grounds to investigate, and in any event, what evidence would they have other than the accounts of the participants? (Adut, 2005) writes about this, and one might gently note that Naomi Wolf has got herself into a little bother over this issue.
However, the police had little choice when offences were reported to them, in terms, during other investigations. Turing's house was burgled, which he reported to the police, and in the course of the investigation he told them that he knew the identity of the burglar. He knew because he had been told by his lover, an unemployed man 20 years his junior: the burglar was his lover's friend.
Under those circumstances, given the legal framework at the time, the police were in a difficult position. A minor academic in a provincial university (remember, Winterbotham's "The Ultra Secret" is still more than twenty years in the future) was telling them about a criminal offence he had committed. They had no option other than to charge him with a crime he had himself told them about. Turing then pleaded guilty, which further removes options from the legal system.
Had John Maynard Keynes, who most certainly was _not_ a minor academic, similarly reported a burglary and in the process implicated himself in a crime, who knows what the outcome would have been? Perhaps his standing in society would have protected him, but we'll never know. There were so few prosecutions for sodomy that discerning a pattern is hard.
Adut, Ari. “A Theory of Scandal: Victorians, Homosexuality, and the Fall of Oscar Wilde.” American Journal of Sociology, vol. 111, no. 1, The University of Chicago Press, 2005, pp. 213–48, https://doi.org/10.1086/428816.