Firstly, to my knowledge, nobody has attempted to storm the cockpit since 9/11, so the locks, though a good idea, haven't actually done anything. And the guns -- projectile weapons not being the best idea when travelling in a pressurized metal capsule anyway -- have certainly never been fired.
The actual improvement in airline security has been greater vigilance on the part of passengers, who stopped both the shoe bomber and the underwear bomber, and better intelligence operations in the middle east, which got us the tip-off about the toner cartridge bomb.
Thus, securing the cockpit gets you more bang for the buck by removing a whole avenue of attack, with relatively low cost (the lock and the gun). While I agree that firing a gun in a pressurized cabin isn't the best idea, having it there makes it very likely that the pilots would have an advantage over any potential hijacker, since keeping other guns off the plane is relatively easy, and doesn't require overly invasive searching.
If no-one's ever climbed over the walls at a prison, does that mean that the walls are "doing nothing"?