This happened by focussing too much on identity politics and not enough on the deprivation, poverty and lack of access to education that affects people in Britain of all genders, ethnicities and religions.
For a while now Labour has focused on radical theories rather than radical solutions.
Overhauling the university system to make it so that everyone can go to university without massive debt.
Overhauling the NHS and moving away from the outdated free of charge structure (that worked when we had lower population numbers) and transitioning towards a French-style mutual/social security funded system so that our health system is fluid and better funded, with easier access and better pay for staff.
Rent caps; Berlin-style, in London and SE cities as well as places like Manchester.
Massive tax hikes on second homes and buy to lets.
Clamping down on zero hour contracts and overhauling the apprentice system for well paid apprenticeships into in demand industries for school leavers.
Basically aggressively pushing for policies to level the playing field for all, rather than dicking around clamouring for more immigration and trans rights and Islamophobia etc would have had them undoubtedly win against the tories. I think we are set for another 50 years minimum of tory government. Unless a socialist party that understands the true meaning of socialism emerges, we are fucked for any kind of opposition.