Not everyone stays in their prime until their mid-30s or late 30s. BJ Penn had an extensive career, lots of wars and there's lots of other factors like genetics, training, drug consumption, mental issues, etc.
NFL players often retire in their early 30s because they already feel the effects and results of not being in your real physical prime anymore. MMA is just more "forgiving" because the athletes aren't that high-level (that's also why the lower-tier athletes in the bigger divisions can fight longer than the (better athletes) smaller ones, look at Oleynik for example.)
Barao is another example. People act like he got USADA'd but the guy just had a long ass career and there's also a mental aspect to it. Some people get better when they lose the belt, some crumble. The guy also never made a dime, dude was probably training in some garage and still washing his clothes in the bathtub when EPOshaw took him out.