In 1967, the Sexual Offences Act decriminalised consensual sex between men over 21 in England and Wales. Before that, a homosexual act was illegal even when it was carried out in private and not witnessed. You can access the Sexual Offences Act in JustisOne UK Core.
Interestingly lesbianism has never been illegal in the UK, although an attempt was made in 1921 to add ‘Acts of indecency by females’ to section 11 of the 1885 Criminal Law Amendment Act which covered ‘Outrages on decency’ between men. You can read the House of Lords debate and the reasons why the move was rejected in the 15th August Commons Amendment available from Hansard 1803-2005.
The inability of homosexuals to have a private life without fear of prosecution was the cause of personal suffering. After being found guilty Oscar Wilde was imprisoned and Alan Turing injected with oestrogen, eventually taking his own life. You can find out more about the lives of both these men if you go to the Oxford Dictionary of National Biography.
Alan Turing received a posthumous royal pardon in 2013 and other men convicted of homosexuality offences which are no longer illegal were posthumously pardoned by the provisions of the 2017 Policing and Crime Act. A Guardian article discussing the pardon and those who were not included can be found in the database Nexis UK, UK issues posthumous pardons for thousands of gay men.