If you buy a house, it doesn't matter how long it took to get built. If you pay someone $10 per hour to build you a house, it very much matters how long it takes, and it would not be ethical for them to charge you twice as many hours as they worked... even if in ignorance you thought it would take twice as long.
Furthermore, while there may be situations where this is a meaningful ethical dilemma, I posit that often a better strategy would be to tell your employer, write on your CV that you've saved (or could have saved) your employer lots of money by automating something, and use it to get a higher paying job where you're not so bored and underutilised. You could then go to an interview and tell them that in the previous job you felt like you there wasn't much of a incentive to excel at a task, and that you're looking for a more impactful position, where your contribution can truly help drive the company forward.