Because parents didn't want to buy an entire flagship smartphone just for their 6yo to listen to music on the schoolbus. But they were okay with buying them an iPod.
iPods were just mid-tier consumer-electronics expensive; which, back in ~2005, was nowhere near entry-level smartphone expensive, let alone flagship smartphone expensive.
Then, after the iPhone started getting rev after rev, Apple's "lean manufacturing" cost-optimizations gradually led to "an iPod" just becoming a particular assemblage of reused old iPhone parts, optimized for manufacturing cost and battery life. All the other iPods died out, leaving only the iPod Touch, there to consume old iPhone parts off the line.
Around six years after that, "a commodity Android phone" became as cheap as an iPod Touch. At that point, the Touch continued to exist mostly due to brand value, and its ability to run iOS games (still a specific / "better" market than Android games, back then), without having to pay for an iPhone to do that.
It's only in the last five years that it began to make economic sense to just get your 6yo who wanted to play iOS games an old iPhone rather than a "new" iPod Touch. It was at the exact moment that happened, that Apple finally killed the iPod Touch.