If you're working for a healthy team/company/manager and have a bit of experience already, you can actively seek this type of work and do more of the things you like. It's just unlikely that you'll be explicitly hired to do this. And as you pick up more of this kind of work, you need to communicate things clearly and make sure that it doesn't look like you're slacking or deliberately looking for lower profile work because that can hurt you too.
Part of that is because I'v become very comfortable diving into very complex, established code bases because of my OSS experience, and enabled by the fact that I've had coworkers who didn't enjoy the deep dive/scaling part of coding compared to adding new features.
A lot of developers really enjoy the spotlight of having added the new killer feature that everyone recognizes, and sometimes that's even different skill set.
So my long winded answer is that there are two main ways to accomplish your goal:
1. Be able to refactor, address technical debt, scale out solutions, debug any problems, and find a team that complements your skillset, and get good at making sure your non visible contributions are known and appreciated. This often means having clear and easily available metrics that can show over time things like: less errors, more tests, faster build times, and so on. Really anything that you can point to that makes it easy to understand your value to those outside your team/org.
2. Become a team lead. A lot of times the tech debt/refactoring work isn't celebrated or recognized, but necessary. The job of a team lead is to both give guidance and enable your engineers to accomplish their tasks. Making code more maintanable, easy to read, and robust ensures your team will quickly and happily progress on their task, and you'll get to share in their successes even if you aren't the one contributing features. Unlike scenario 1, you don't necessarily even have to show as many metrics, as your value proposition is much simpler: Make your team productive and happy.
A couple of thoughts:
- If you work on open source projects, you can create and tweak this role for yourself by finding needful tasks in upstream projects; just be careful to validate your approach to make sure your changes are likely to be accepted
- If this were a role within a salaried organization, you'd ideally want a way to show -- or a shared consensus -- that the work involved is worthwhile and producing value. How would we do that for software projects?
Some people will tell you that they dont allow developers to refactor because its risky and there are higher business priorities, but before you listen to them, ask about the context. My team's official line is no-refactor because we can't break our API because our support contracts are 5+ years. That's true, but under the hood we are refactoring a little every day (split a giant method into a few new classes, add wrapper classes so we can add a unit test to previously untested code, etc)
Also, if you're good at the skill "good at reading bad code", your teammates at any job are going to be very grateful! There's not a lot of people are good at it and enjoy that!
IMHO, it's difficult to get such job. Specially in today's world where technology is changing at very rapid pace.
In my case management philosophy have always been "why fix things that aren't broken" or it will be responsibility of next person.
YMMV
maybe just start out part-time.