According to a segment of BBC Radio 4 (Could have been 'Today', or 'PM', or an NHS manager on ?call You and Yours) , it is partly due to lack f adequate nursing/care-home provision. If there are no care home places, the NHS can't discharge elderly people, who take up (expensive) hospital beds. This has knock-on effects, such as A&E being unable to transfer patients to wards, so ambulances wait outside A&E. It's obviously a little more complicated than that, but that is a
partial answer. In addition, Covid-19 had the effect of many people postponing treatment, either voluntarily, or out of necessity, and now the backlog needs to be dealt with. Pre Covid-19, the bed occupancy rates in general were very high (I think aiming at 95%,
Nuffield Trust: Hospital Bed Occupancy; maze of statistics here:
https://www.england.nhs.uk/statistics/statistical-work-areas/bed-availability-and-occupancy/), which meant there was little slack in the system to accommodate excess demand. So a small rise in demand causes very long queues.