It is 1.5 trillion OVER SEVENTY YEARS (in 2020 dollars) for every cost associated with the plane. That number includes design and manufacturing, fuel, munitions, maintenance and every other operational cost over the lifetime of the program. The plane is superior to anything else in the sky except possibly the gold-plated F-22 (and it is a hell of a lot cheaper than an F-22.) Sunk cost indeed...
The use of the gun is perhaps 1% of the role of this fighter. The number of times a fighter has used a gun in air combat in the last 30 years is non-existent. For strafing, (generally out of favor for CAS due to non-combatant casualties) the gun is inaccurate. This will be updated with a software fix.
If you read the reports of pilots flying the aircraft during Red Flag and other exercises, the plane is excellent. But there's a continual axe grinding over this plane that is factually inaccurate.
In aviation every kilogram of weight is costing a lot, carrying a useless gun is pointless. If the gun use is too low to make it accurate, it is better to completely eliminate that quarter ton of metal.
Politics and institutional inertia will often overwhelm engineering. The USAF has a strong memory of deploying the F-4 Phantom to Vietnam without a gun. They believed that the Sparrow (AIM-7) and Sidewinder (AIM-9) were mature enough to win most encounters. Turned out not to be the case, and gun pods were quickly designed and shipped out. These aren't optimal since they induce a significant amount of drag, as well as taking up an external mountpoint.
So since then, the idea has stuck around that a fighter must ship with a gun. The F-35A models have internal guns, while the B (STOVL variant) and C (Naval variant) can use an external gun pod. This is a tough engineering task since the pod needs to be stealthy.
The value of the gun on all three variants is really limited IMHO. The F-35A only carries 182 rounds, and the B/C gunpod 220. That's just not much ammo for CAS, nor even A2A engagements.