In any war, the strategic goals (and logistics) of the war defines what is worth doing and what is not. The same is true of sieges.
Environment: Pre-gun fire, the only way to raze a city was to (maybe sack it first and) burn it to the ground. Urbanisation of the country side moved more people into cities making them bigger. Now, guns could destroy large portions of a city but not fully. There should be cover, sneakaways, places to hide either bombs or snipers or small units for ambushes. Even fires would stop and not travel as far as they used to -- steel and concrete do not burn that well. So, you have more people and an environment where they can fight effectively. Add to this easy to use weapons (see below) and you the means to do effective urban warfare.
Strategic goals: Now, both Stalingrad and Warsaw were highly political targets that both sides really wanted to keep. Stalingrad because it was Stalin's City and losing it would have been a propaganda disaster. Warsaw because it was the Polish government's in exile (in London) way to assert control over Liberated Poland against the Soviet Union (veiled?) attempt at conquest. Keeping or liberating the city were war goals worth of the nightmare of getting into urban warfare.
As ever, it comes to the overall strategy of the war whether a battle is worth it or not.
A modern example: In more modern times, Baghdad fell to armoured divisions which was thought to be utterly impossible. Again, the goal of the defenders was to flee and create a civil war, not fight for the capital. Thus no major urban war within Baghdad happened. Maybe that helped with the above statement, maybe not. It's too early to tell. Was Baghdad seen as a strategic goal by the US? Yes. Was it seen as a strategic goal by Saddam forces? Maybe. Was it seen as a strategic goal by Al Qaeda? No. Again, it comes down to overall strategical goals.
Side note: Finally, firearms are much easier weapons to use than swords, bows, spears, crossbows, and co. They require limited expertise (thus why the Kalashnikov is so popular because it is so simple) which you can train easily. Its effects are hard to protect against. It takes a few minutes to be able to shoot, a few days to become competent. Thus your civilian population can learn to defend itself really quickly. Explosives need good bomb makers, the delivery system can be dumb -- see suicide bombers, IEDs, mines, etc...