Is it always better to remove/replace inefficient jobs? For example if a company employs 100 people to do manual data entry, would it be better for either the economy or the utility function to fire them and automate the jobs?
There's enough sublety and variance in benefits (to employee, employer, and/or customers) of "a job" that I don't think there's any simple answer. In most cases, the benefits are not evenly distributed, so you hit the problem of interpersonal comparison - if you hurt 100 and help 1000, by hard-to-measure amounts, is that good?
My ideal definition of "job" is "opportunity to perform/produce something of value to others, and to capture enough of that incremental value that you're better off doing it than the next-best thing you could do with that time/effort".
It's clearly better for the company's owners, the company's customers, and the company's vendors to automate: things are faster and more accurate without manual data re-entry. Some of the 100 laid-off employees will benefit by the realization that there's easier or more rewarding work they can do (improving the automation, or harder-to-automate data entry somewhere else). Some of them will be harmed because that opportunity no longer exists, and their next-best opportunity is not as rewarding.
Is it overall beneficial? Depends on your aggregation function. But it doesn't really matter - it's enough improvement to customers and vendors that the company needs to automate to stay in business at all.
I shouldn't have used a company for my example because as you illustrated that's not a very interesting case; if it wasn't a company but the government (e.g. the TSA), does economic theory say those jobs will come back in a more efficient form?
Even without competition, the flow of constrained resources still applies. Public or private, no theory says that the jobs will come back in a more efficient form. The theory does say that _someone_ always pays for inefficiency.
In the TSA case, customers/travelers suffer greatly, and taxpayers as well. Employing fewer humans would benefit some of them (by motivating them to find jobs that are better for them), and harm some (by forcing them into the less-rewarding next-best job they can find), just like in the company case. And it would benefit customers and owners(taxpayers), just like in the company case.
Whether humanity overall is better off with that efficiency is a question of aggregation, for which I don't think there is an objective answer. I believe that, in almost all cases, efficiency is an improvement for the median and average human, when measured on decade timescales, even when it seems a loss for shorter timescales or subgroups.