Sure, if companies could do without paying programmers, they would and should.
That doesn't change the fact that they continue doing so (at least for now) because they see it as a good deal. Programmers are responsible for continuing to have skills that are marketable if the economy changes.
>> "right up until it's eliminated"
This phrase implies an Evil Power is deciding who gets to live or something. In reality, a job is "the opportunity to meet a demand by selling labor." It's not unjust to stop demanding something.
When people stopped wanting top hats, that wasn't unjust, even though it meant hat-makers needed new jobs. If people stop wanting software, it won't be unjust, even though it will mean programmers need new jobs.
I'd love for my house to produce its own electricity so that I could fire the power company, but until that seems easy and cost-effective enough, I pay for power because I think the money I spend gives me outsize benefits. Same with my employer paying me.