The Gaza Strip seems very poorly served by the Palestinian Authority, let alone Israel. But, the area has relatively stable borders and it would likely have a stable government in Hamas. So, what if Gaza just declared independence as the government with sole control over the Gaza Strip?
Would Gaza get recognized by other countries? Could it parlay the recognition into forcing a permanent peace with Israel as becoming a recognized country puts Israeli treatment of it into more known sections of international law?
‘legitimate government’ isn’t really a thing. Many recognized countries are ruled by hereditary governments, or by autocrats who gained power in a coup. The legitimacy of such governments, andthe nationhood of the states, is recognized by other countries based on the foreign policy (mostly self interest) of those other countries. So, if you want to guess who would recognize a Gaza nation with Hamas as the ruling clique, ask yourself what governments would benifit from doing that.