There are a lot of opinions on this topic. But I recently found this video from Edelrid and thought it did a good job talking about when to potentially retire a rope.
I recently retired a rope. But before I got rid of it completely, I chopped the rope at both ends to shorten it by about half. From there, I used it as an indoor climbing rope for a while. Eventually, I retired the rope completely.
One important thing that the video doesn't discuss is how to retire a climbing rope. In my opinion, the best way is to chop it up into unusable lengths. That way, it can never be mistaken for a functioning climbing rope. Or, you can find someone who reuses ropes for art projects, like Hyalite Designs.