Edit; comparing the logic of a 'but for' vs a 'necessary' condition. Was the F-35 necessary for threat mitigation. No. Was it framed as the necessary for cost savings, yes.
The F-22 is an air superiority fighter. The F-35 is a multi role strike aircraft. The F-22 would never be allowed for export, because it has features we don't want to share even with allies. The F-35 was designed for export to allies from day one.
There's no scenario where just buying more F-22's made more sense than building the F-35. The F-35's project problems, primarily driven from the joint acquisition strategy are their own thing, completely independent of the F-22.
So, the real question is if the F-35’s should have had fewer versions and thus been more capable in it’s remaining roles.
For the shuttle to get approved, it had to meet the demands of many masters. The fact that it had to meet DoD missions as well as NASA missions made it a bit of a boondoggle. Likewise, the JSF needed to meet the Marine Corps demands of VTOL to take the place of the AV8B.
It's hard to remain focused when you have so many stakeholders. As the saying goes, a camel is a horse designed by committee.
I think we're saying the same thing. The argument is, "Was the F22/F18/Fwhatever/weapon-system necessary for threat mitigation? Yes."
With that said, if proponents of the F35 want to frame it as "threat reduction + cost savings" that's how they get the budget approved. But the point stands that without a threat, there's no basis for the cost savings argument. I'm not saying it was effective as cost reduction.
To circle back to the original point, it's much easier to get a budget approved when the basis is existential threat, rather than "science is cool."