Generally, a gangster is only going to try to control a fairly narrow area - for example, the Mafia did not try to control through most governing functions; they controlled the flow of drugs and prostitution, and often would cover a fairly small range of businesses through “protection”. While they might own or control a garbage collection franchise, and they might try to influence the legitimate government in the area that was franchised to the garbage company, they did not attempt to actually be the government. They tried to influence the legitimate government through bribes and force for what they perceived was their needs, but they did not become the government. They were more like a sub-government.
The governing body will let you know who they are. Whether it is elected, as here, or elected through electors whom we choose, as here, or appointed by a king, or ruled by junta which is installed by an army, or chosen or established by some other means, you will know who they are.
As to cooperating with them, you might want to make a study of some of what has gone on in the last 40 to 50 years in Central America, as it has been a hotbed of regime change, often by the gun. Further, most of it was not established as clearly by a vote of the people, as “people”, those having the right to vote, was not universal.
The bottom line is that you can cooperate or pay the consequences, or join the armed opposition. That last option often is seen as highly romantic by the young and the uninitiated; which romance often lasts until the start of the first fire fight.
One can talk till one is blue in the face about the morality of paying taxes to a junta or military dictatorship. Morality is too often not particularly clear in the issue as there will be those who are very pro-government and those who are very anti-government, and it is less than easy to presume that one can say that either the existing government or the “loyal” (or not so loyal) opposition has the high ground in regards to morality.
Read about the Sandinistas; many painted them as heros of the poor and the working poor. The paint was a bit thin… which is not to say that what they sought to replace had any greater moral suasion.
The bottom line is that the use of the word “legitimate” is fraught with too many implications. The practical matter is that whoever is the government is the one you will pay your taxes to or pay the consequences. And the presumption that the opposition is going to be better is most often a fantasy-land dream.
If you will, quickly say who should be the government in Iraq - those who have been elected? And how is one to make a working government with groups who have literally centuries of history of being at each others’ throats? And if the elected coalition falls to the terrorists, will you then say that they, the terroroists, are not a legitimate government? At the risk literally of your life?
Or look at Afghanistan; we have replaced the Taliban with a series of tribal lords, again with the same history of killing and pillage over centuries, and the Taliban are back at it trying to regain control. They had a theocratic form of government; one that is more rigid than your wildest imagination, and many supported it. Which one is legitimate; or which one is more (or less) legitimate?
You are asking an esoteric question that is great for long philosophical discussions over a pint of good ale, and meaningless beyond the doors of the pub.
I have seen the era of the hippies - Luuuuuv one another, grow hair in your armpits and don’t shave or get a haircut, wear clothes that a rag picker would pass up, engage in tie-dye and candle making, wear sandals, eschew big business, form a commune and go macro-biotic in diet, smoke some dope, and Luuuuuv one another.
Communes seem to have fallen out of favor, in part because they either turned into a dictatorship (benevolent for the most part, but not all), or couldn’t make their collective group-grope form of decision making work because when it gets right down to the nitty gritty, the exteme majority of everyone else had a life.