I have about 15 years experience professionally as a software engineer, in all kinds of companies, at all kinds of different seniority levels.
I call bullshit. Your task is to deliver a project that does what it's supposed to, all in a timely fashion. You do whatever it takes, including getting rid of old code and rewriting stuff if it makes you more productive overall.
Writing code that does what you want is much faster than taking someone else's code and twist it to do something it was not written to do.
You should always be very careful about what dependencies you use, as most often you will have to deal with their limitations and bugs, and they could kill your project.
If you had 20 separate people who contributed to the same thing and left then you most likely have huge code debt. Managing that sort of thing is a daily task for any software engineer. Apparently your strategy is to just add debt onto the pile and put your head in the sand pretending it's not your problem. Instead you should plan tactical refactoring moves to make the codebase leaner and better able to adapt to the business needs, all without breaking any existing functionality and workflows.
You're asking "when". That's the wrong question. It's up to you to manage your time and invest it into tasks that help you save time later on. A software engineer is usually not paid by the hour either, so you just do the work until you're satisfied with the effort you've put in.