Reading list: How Does Test Driven Development Help in Maintaining Legacy Code?
Test Driven Development helps in maintaining legacy code by making changes safer and more controlled. Legacy systems often do not have proper tests, which makes updates risky. With Test Driven Development, developers first write tests around existing behavior, so the current functionality stays protected.

Using Test Driven Development reduces the chance of breaking old features during updates or refactoring. Tests act as a safety check and quickly show errors. It also improves understanding of legacy code, as tests explain how the code works. Overall, Test Driven Development makes legacy systems more stable, easier to update, and simpler to maintain over time.
https://www.samyak.com/news-post/test-driven-development/