It seems the wiki entry on the battle leaves the question open to debate with this quote:
On July 23, 1942, Hitler personally rewrote the operational objectives for the 1942 campaign, greatly expanding them to include the occupation of the city of Stalingrad. Both sides began to attach propaganda value to the city based on it bearing the name of the leader of the Soviet Union. It was assumed that the fall of the city would also firmly secure the northern and western flanks of the German armies as they advanced on Baku with the aim of securing these strategic petroleum resources for Germany.[15]:p.528
TL;DR - For Germany, a defeat at Stalingrad meant losing access to the resource-rich region of Caucasus and a heavy blow on its armies' morale.
Germany was mostly dependent on imported oil. With the start of the war, it lost its supply from both the Middle-East and the USA. The main supplier from then on was Romania. Germany still produced synthetic oil, but with the allies' strategic bombing of the necessary facilities, that was lost too.
With the failure of the Operation Barbarossa and the dragging of the fighting in the Eastern Front, Hitler needed supplies to maintain his armies. The region of Caucasus was very rich in both rare-metals (needed for the industry) and fuel - the oilfields in Azerbaijan, mainly. So by controlling the region, Hitler would be getting the supplies he required and depriving the Soviets from them. That was the reasoning behind the Case Blue offensive.
The easiest way to access the region was through southern Ukraine and the Caucasus. This meant leaving the back of the attacking army unprotected against Russian counteroffensives. To prevent it, Hitler decided to split Army Group South into two: Army Group A would advance towards the Caucasus and Army Group B would hold the line at the Don River and strike into Stalingrad, which controlled the movement of supplies in the Volga River(map); at the time, Army Group North and Center were engaged in Leningrad and in Rzhev (near Moscow), respectively.
The resistance mounted by the Soviets in the city of Stalingrad started to drain more and more resources from the Germans and what started as a minor engagement in the Campaign, ended up being the focus of it. With the number of troops and supplies already invested in Stalingrad, leaving the offensive would mean that nothing would stand between the Russians and the German armies in the Caucasus, which would be encircled. With that in mind, I would say that the prolonged fighting for the city was due to its strategic importance. I don't think that the Germans would engage in close street-fighting - since the bombing of the city reduced it to rubble and denied the advantage of using armored vehicles -, which was decidedly not favorable to them, only for propaganda purposes.
I'm sorry for the broken English. I haven't written something this big in a long time.
There seem to be two parts to your question:
Why did Hitler revise the campaign objectives to include the capture of Stalingrad?
Why did Germany and the USSR continue to commit so many resources to the fight even after the costs of doing so were evident?
Cutting Soviet lines of communication along the Volga by capturing Stalingrad would have been a major blow to the USSR by disrupting the flow of oil from the Caucasus and complicating delivery of lend-lease supplies. However, denying the oil fields to the Soviets was not Germany’s primary strategic goal in 1942. Instead, the goal was to capture the oil fields for Germany’s own use. From Fuhrer Directive 41, Hitler’s initial orders for the 1942 campaign:
All available forces will be concentrated on the main operations in the southern sector, with the aim of destroying the enemy before the Don River, in order to secure the Caucasian oil fields and the passes through the Caucasus mountains themselves.
The capture of Stalingrad was not a key objective of this original plan. The thrust of the plan was for German forces to encircle and destroy Soviet forces around Voronezh and along the Don, which the Germans believed would open the road to the Caucasus. Advancing on Stalingrad was a secondary objective in order to cut the Volga and to destroy factories in the city, but taking the city itself was not identified as critical:
The third attack in the course of these operations will be so conducted that formations thrusting down the Don River can link up in the Stalingrad area with forces advancing from the Taganrog-Artelnovsk area between the lower waters of the Don River and Voroshilovgrad across the Donets River to the east. These forces should finally establish contact with the armored forces advancing on Stalingrad.
Should opportunities arise during these operations, particularly by the capture of undemolished bridges, to establish bridgeheads to the east or south of the Don River, advantage will be taken of them. In any event, every effort will be made to reach Stalingrad itself, or at least to bring the city under fire from heavy artillery so that it may no longer be of any use as an industrial or communications center.
In July, Hitler expands the objectives of the campaign to include the capture of Stalingrad, as well as the capture of the entire Black Sea coastline and the western Caucuses. There are strategic rationales offered for each. In the case of Stalingrad, Hitler wants to cut the Volga, but he also identifies a need to strengthen the German position along the Don and to destroy concentrating Soviet forces that might threaten the Army's flanks. Fuhrer Directive 45 lays out the new objectives:
In a campaign which has lasted little more than three weeks, the broad objectives outlined by me for the southern flank of the Eastern front have been largely achieved. Only weak enemy forces from the Timoshenko Army Group have succeeded in avoiding encirclement and reaching the further bank of the Don. We must expect them to be reinforced from the Caucasus. A further concentration of enemy forces is taking place in the Stalingrad area, which the enemy will probably defend tenaciously.
The next task of Army Group A is to encircle enemy forces which have escaped across the Don in the area south and southeast of Rostov, and to destroy them. … After the destruction of enemy forces south of the Don, the most important task of Army Group A will be to occupy the ; entire eastern coastline of the Black Sea, thereby eliminating the Black Sea ports and the enemy Black Sea fleet. … At the same time a force composed chiefly of fast-moving formations will give flank cover in the east and capture the Grozny area. … Thereafter the Baku area will be occupied by a thrust along the Caspian coast.
The task of Army Group B is, as previously laid down, to develop the Don defenses and, by a thrust forward to Stalingrad, to smash the enemy forces concentrated there, to occupy the town, and to block the land communications between the Don and the Volga, as well as the Don itself.
Implicit in these new goals are the recognition that the Soviet ability to resist has not been destroyed according to plan and overconfidence in the German Army’s ability to finish the job. The German Army so far has had stunning success breaking through Soviet defenses and assumed it was only a matter of time before the Soviets collapsed for good. However, the Germans consistently underestimated the forces available to the Soviets. Hitler also fails to recognize that overextended supply lines were a major factor in German failure to pin down Soviet forces so far, a problem that would only get worse. Finally, Hitler convinced himself that troops from Germany's allies—Italy, Romania, Hungary and Croatia—would adequately substitute for inadequate German force strength, which was a disastrous mistake.
The net result is that the strategic vision for the campaign becomes muddy. It's not clear that capturing the oil fields was ever a viable objective for the Germans, given the distances involved and the Germans' inadequate force strength and supply network. The revised plan probably ruined whatever chance the Germans had, however, by diluting already-thin German forces along two distinct axes of advance.
Obviously, the Germans then fail to capture Stalingrad. So why do both sides commit so many forces and sacrifice such huge numbers in the ensuing battle? The Soviet side is easier to understand—as others mentioned, losing the supply lines up the Volga would be disastrous. Stalin issues Order 227, “No One Step Backwards,” and the Soviets dig in along the river. As early as September, they also recognize that keeping the Germans pinned down in the city creates opportunities for counteroffensives, which eventually becomes Operation Uranus.
The German decision to remain committed is harder to understand. Propaganda and the name probably play a role. However, I think the better explanation is that it’s very difficult under the best of circumstances for commanders to recognize when they’ve made a strategic error and to correct it. Once forces are committed, it becomes harder and harder to admit the original plan was flawed or that the effort was wasted. That dynamic is reflected in both Stalin and Hitler’s repeated refusal to let their armies retreat, even when doing so would have preserved forces for use in stronger defensive positions.
The result in this case is tunnel vision about capturing the city. If the Germans’ operating assumption is that the Soviets are on the verge of defeat and running out of reserves, than victory is always just one push away. The balance of costs vs. benefits or alternative approaches are not considered. Even commanders that recognized the risks were unwilling or unable to get their voices heard. After the Soviet breakthrough, the command climate around Hitler becomes increasingly surreal as Hitler convinces himself the Sixth Army can be supplied by air and that adequate forces exist to regain the German's original line.
TL:DR – Early successes in the 1942 campaign led Hitler to order the capture of Stalingrad in order to destroy Soviet Forces and cut Soviet supply lines. However, he overestimated the German Army’s capacity to accomplish the objective. Once committed, he refused to admit his error and instead continued to reinforce failure, condemning the Sixth Army to destruction.
Key Sources:
Antony Beevor, Stalingrad: The Fateful Siege: 1942-1943
Williamson Murray, Allan R. Millett, A War to be Won: Fighting the Second World War
edit(s): Damn typos.
I would just like to add that National Geographic has an interesting documentary on Stalingrad -- Generals at War: Stalingrad. It takes the point of view of Generals Chuikov and Paulus, and while it does have quite a bit of fluff and added dramatization, it does a reasonably good job of discussing each sides' strategy and goals for taking Stalingrad. It also has some interesting graphic and map recreations. NatGeo made a 'Generals at War" for the Battle of Kursk, too.
Both dictators wanted the city for obvious reasons. Hitler in private conversations with his generals would often recite production numbers and transport capability of Stalingrad but that wasn't really the issue, just a good excuse.
Mannstein's book "lost victories" has some very interesting chapters about Stalingrad. Mannstein often laments the lack of flexibility of Hitler regarding cities and gained terrain in general and his inability to let go of them even in tactical manouvres.
Mannstein himself was convinced that the way the Armies around Stalingrad and the rest of the South where deployed was a catastrophe waiting to happen (and it did). In fact the los of Stalingrad almost doomed the entire Southern Army in Russia, if not for Mannstein and the stuborness of the German soldier.