Why didn't they stop Dallas at its peak ?
That kind of thing seems easier to say in hindsight. And also when you're not financially benefiting from the show in any way. As
@Billy Wall said, most long-running TV shows weren't considered as good, quality-wise, by the time they ended. It's sort of the nature of storytelling. Characters, storylines, jokes, etc. all begin to get stale. The phrase "Jump The Shark" came about because it describes of many shows tend to start resorting to "stunts" to try to re-invigorate interest.
But if you're a producer, or star of a show, or you're the Network exec it can be really hard to decide to end a show that's still making you money and getting good enough ratings, even if it's not as much as before. That's why ending it at its "peak" is not easy because if it's really at its peak that means it's still doing well so why stop it? A couple of more recent shows immediately spring to mind, both also on CBS like Dallas was. Two and A Half Men and How I Met Your Mother. The former should have ended when they got rid of Charlie Sheen. The Ashton Kutcher character made no sense in that dynamic (and they knew it, as the eventual series finale had all the characters making jokes about how dumb the premise of the show was), yet the series remained one of the highest-rated sitcoms on TV so they managed to squeeze four extra seasons out of it. HIMYM had a unique premise, with a pre-planned ending point right from the start, that should have run its course at least two seasons earlier than it did. But the show kept getting good ratings so the network kept renewing it, so the writers had to keep dragging out and recycling storylines until they could finally reach their pre-planned ending. This is what often happens.
Or a current CBS show, MOM. They just announced they're ending it, which is what I thought they should have done once Anna Faris decided not to come back for season 8. But it was still a hit so they tried to keep it going, but I guess season 8 hasn't performed as well as they'd hoped without her, so
now they're ending it.