This question gets asked fairly regularly; I answered it a while ago here, with links to answers by other users. The short version is that many philosophers were members of the leisure class and did not need to work for a living (though it was also in vogue to adopt an ostentatiously austere lifestyle).