You're not wrong in that the land value often isn't in line with the shacks.
But a few things to consider:
One is that shacks tend not to be built by the owners on their own land. i.e., they're not paying for the land, therefore the value of the land plays does not prohibit them from building a shack there. Instead, they're occupying the space illegally. A shack only costs a little in bricks (these lowgrade ones are probably about 10 cents a piece) and some metal roofing.
Second is that shacks in some countries are built in high-demand locations as a political and economic instrument by poor people. In Morocco for example, those who live in slums often get bought about for about 25k per family by a public-private investment project aimed at building luxury apartments. They then take this money to build/buy-into a low-quality apartment building in the city's poor periphery. They're often staying illegally and refusing low-ball offers. If you kick them out by force, you have a moral and socio-political problems and the problem only relocates (waterbed effect). Further, local politicians will often cater to these people for their votes, when the majority of the country is below middle-class, that's who you pander to. In essence, these slums and the related buyout acts like a sort of earmarked social-housing tax on luxury housing projects.
Sometimes the slums are actually owned by those who live there (unlikely, usually it's based on forged documents). But even then, no developer will buy a small plot in the middle of a slum for luxury apartments. You need to be able to buy-out families consisting of hundreds of people before you have a large enough plot of land to develop in. That isn't easy and people know they can fetch a high-price. They also know they have to, finding another place to live isn't cheap.
And lastly, there actually are tons of shacks being sold every day, replaced by apartments due to the value dynamics you described. It just doesn't happen overnight to the entire stock.