Usually, leaders of either House try to avoid votes they cannot win. But sometimes they calculate that there is a political benefit even in losing. In this case, Speaker Pelosi was convinced that even in losing, the long term political benefits are such to the Democrat Party that the symbolic effort of the override attempt was a net positive.
The Democrat base voter is as strongly against the President as the base Republican voter is supporting him. In the battle for public opinion, that leaves the independents in the middle to determine the outcome. In the case of the Iraq War, the middle is pretty much in favor of ending American involvement, but they are aware of the consequences of doing it the wrong way. Being too hostile to the President could be dangerous for the Democratic leadership with this group. This group would prefer to see both parties working together to come up with a solution.
However, many Democrats worry that the “Howard Dean wing” believe they are not being sufficiently aggressive in their efforts to end the war – the symbolic votes earlier in the session to protest the war created frustration that the turnover in Congress would “talk the talk, but not walk the walk.”
By attempting to override the President, the Democratic leadership can claim to their base voters that they took the issue of withdrawal as far as they could, leaving no stone unturned. They simply didn’t have the votes to succeed. So, when they ultimately compromise and give the President pretty much everything he asked for, they can go back to claiming that they “support the troops but oppose the war,” – a position that has more appeal to the middle.