That's the trillion-dollar question, isn't it? If we knew precisely what determined the GDP of a country, development economics would be a solved problem.
But I can tell you some things that most economists believe are important to the development (or lack thereof) of a country's GDP.
The first is institutions. In order to achieve and maintain prosperity, a country must have institutions that support economic development, which generally means some form of democracy and free market economy. The precise form can vary (Switzerland is more democratic than the United Kingdom, while the United States has more free markets than France, yet all are about equally prosperous), and there are some exceptions, especially in the short run (Saudi Arabia has horrible totalitarian institutions, but will remain wealthy as long as the oil continues to flow). But in general, you need to have a free government and a free market if you really want to achieve a high level of economic development.
Does Madagascar have these things? Not really. Madagascar has a moderately free government with a high level of corruption, and in the 1970s implemented a number of socialist economic policies that undermined investment and stunted economic growth. Starting in the 1980s many of these policies were reformed, and Madagascar transitioned to a more liberal export-oriented economy. But with corruption high, investments intended to support growth have been skimmed off to line the pockets of individual government officials.
Which brings me to the next two key features: infrastructure and education. Successful economies always have a large infrastructure base of roads, rails, electric power, and clean running water; most regions of Madagascar have none of these things. Prosperous countries have educated populations where almost everyone is literate and a large fraction go to college; Madagascar has hardly anyone with college degrees and a large fraction of the population who are outright illiterate.
Trade is another important source of wealth, which Madagascar has had trouble maintaining due to their geographic isolation. Their large sea coast could help with trade (it is certainly better than being landlocked), but they are very far from most of the major trade hubs like Tokyo, New York, London or Singapore.
Notice what I haven't mentioned: Land or natural resources. Madagascar does have many natural resources, but these actually turn out not to be all that relevant to economic development. They don't hurt necessarily (at one time economists actually thought they did hurt, an idea called the "Resource Curse", but it turns out that the problem isn't the natural resources per se but the extractive institutions that tend to build up around them if they are the only source of wealth. The US and Norway are quite rich in natural resources, and they do just fine because they have sound institutions.)
To make matters worse, Madagascar has a long history of colonialism and extractive institutions, starting centuries ago with French colonization. Even after independence they were never fully able to shed these institutions, and still have an economic system that works better at enriching a small few than it does at achieving overall prosperity.
Reforming Madagascar to achieve economic growth will be no small task, but we must not give up hope. Other countries such as Korea and Japan have lifted themselves out of similar levels of poverty in the past. Once we figure out exactly how, perhaps we can achieve it elsewhere as well.