If a person demonstrated that he can create software that can do the job of a human at a fraction of the cost, why on earth would a company get rid of that golden goose?
I've had a lot of time to think about that (been unemployed for a couple months now), and have come up with a few reasons.
* All of your reputation within an organization can vanish following the wrong change in management (especially executive management) or organizational structure. A new manager may take for granted all the great things you automated if he/she never saw the prior pain and inefficiency. That new manager may then look at you, see someone who doesn't have a clearly defined role anymore, and fail to understand the long-term value. You can only sell yourself for so long; if you can't pull another magic rabbit out of your ass for the new management, and quickly, then you'll be gone.
* Once you've automated yourself out of your own job, naturally people will notice and you'll start getting invited to work on other problems throughout the organization. In domain professions, which are often occupied by folks who have been doing things the same way for decades, this can be hugely intimidating and even threatening for others. I've been aware of this throughout my work and have always sought participation and consensus from those who might be affected by my work, but some minds are easier to win than others. Combine a few of these bad apples with the above change in management, and poof.
At my first office job I was able to script away a lot of my work. But...it was my first office job and while I had the skill, I didn't know how to sell myself. I didn't know what to study or work on to move forward yet. If I had to do it over, I would have introduced myself directly to more people in that department and learned their stack to get some direction. I would have tried to convince them to make room for non-senior devs.
I did try to move up, but I talked to all the wrong people who couldn't see the value in my skills.
I ended up getting an entry-level programming gig somewhere else.