There’s a tired joke one might hear in a restaurant when your meal is taking too long which goes something like “I guess they had to go catch the chicken before they could cook it.” This doesn’t actually happen in restaurants (probably), but it does happen in software development all the time.
When you want to do something new, you rely on having a significant chunk of code to build upon. But occasionally you have to go back and fill in things that you never realized you needed. Thankfully, unlike the restaurant joke, it’s not always such a great time sink. Having to go back and rework previous code can be done with the benefit of hindsight, and often lets you maybe make some low-effort changes that impart significant improvement to the software.