I don't see it as a mistake at all.
His motivation for the day-to-day grind of the tour was no longer there and, heading into that US Open, he had not won a title in over two years (previous was Wimbledon 2000).
He played a great tournament and found himself in the final against his greatest rival. Your final match being a Major win in your home country, to tie Connors for most Open-era US Open titles, against your biggest rival sounds like a fairytale. He took a year to officially decide, but I think he realised it was the perfect way to bow out.
He had the highest number of Majors and it is not as if he was going to win the French. For most, he was the greatest player of the Open era at his retirement. For me, he was second only to Borg and the greatest fast-court player of the Open era. Not too shabby.
People spend so much time on here dismissing whoever they don't regard as the absolute best as if they are a joke. Now with Federer having surpassed Sampras in the eyes of most, people think he should have continued. I strongly disagree.
A superlative career with a spectacular finalé, the likes of which we will possibly never see again. It will always be one of those great sporting moments.