Just to get that straight: Legacy code is practically always large code with countless hidden requirements, and with insufficient or no tests and without documentation. But which works somehow. Any change needs to meet numerous unwritten requirements, and it can often only be tested in the real world. If you have N features, you have N*(N-1)/2 interactions between two features, so it is quadratic growth with N. This is why it is very hard and time-consuming to change.
It shouldn't be that way, but writing large software - especially in commercial environments - is often like climbing a high roof on a ladder, and then throwing away that ladder. Modifications are only incremental, and usually not documented. Incremental modifications are one of the only two working engineering approaches for software we know - and the only one used for commercial software.
The other way - which is used in aviation for example - is to specify, document, and test everything, right from the start.
Now the problem is you can rewrite legacy stuff as much as you like, but it is near impossible to make sure that large changes work. Because in order to do that, you would need to run the tests that do not exist, or create tests from specifications and requirements which do not exist either.
And GenAI tools are not going to change that. The agentic tools kinda work by filling in missing requirements with assumptions and average observed stuff. It can generate reams of code, fast. But while this kinda works for a small phone app, it doesn't for large complex stuff. If the code does not fit in the head of one person working for months on it, it will never fit in the context window of an LLM.

