You don't have to stop playing. Kasparov (59) still plays here and there and he's still pretty great. Anand is 52 and is 13th in the world.
Chess requires a crazy amount of time invested and you're likely going to stop, and definitely slow, making gains at a certain age. Lots of people play chess for reasons other than becoming the world champion (since obviously most won't).
That said I play online chess too much and it's sort of a waste of time ;)
Yeah, it's sad to see champions giving up chess in their 30s but I can also see the desire to leave on a high note, before you've declined, and also spend your life on other things- you've already shown you're the best so why invest all that time and effort into keeping your title? There's definitely diminishing returns.
If you're talking about competitive players, they don't give up, they stop competing professionally and usually go on to teach. Competitive chess is a gruelling full time job.