Evolution is, ultimately, random. The populations you get are random, and the traits they develop are random. You can frame evolution as an “optimizing force” because statistically, creatures with bad traits die off faster than creatures with good traits, letting the good traits spread around the population, but evolution is entirely blind and deaf to any end goal, and there is no slot called “dinosaur” it would be trying to fill.
Whatever works, works. Last time, dinosaurs happened to fit the niches. When the environment drastically changed from the meteor impact, most of the large ones couldn’t adapt and died off, which led to mammals eventually taking over most of their niches.
Also, all dinosaurs didn’t die off. Smaller species are generally more tolerant to changes in the environment, so they survived and continued to adapt just like mammals did which is why we have birds. The only reason you don’t call a seagull a “dinosaur” is convention.
Latest Answers