I used to work in a local planning authority so I have a different perspective, but developers have to commit to about 30% of their housing being affordable or social when they get the contract.
Typically about half way through the developer will cry 'viability', which involves them claiming the build has cost more than they expected, or sales won't reach projections, so they need to sacrifice some of the social housing to build more luxury and make up for the "loss". They might also pivot and say they'll contribute community assets in other ways, like building a garden or renting out units to local businesses.
The local authority is reliant on S106 payments from these developers, which are basically lump sums for community infrastructure that the council uses to keep things like transport, schools, parks and other services running. The bigger the development the bigger the cheque.
The councils are underfunded and desperately need that money, so if the developer pulls out or abandons the project they're fucked. So they say alright, fine, you only have to build 10% affordable instead of 30%, as long as it means you'll finish the project and pay for our local infrastructure. They know it's BS but the developers have powerful lawyers to fight their case and the councils.. well... Don't.
So this is how you end up with thousands of luxury flats in places like Battersea which are supposed to include affordable homes for local people, but in reality are bought up by foreign property investors (or mugs like Grace), and the housing crisis goes on.