True. Sometimes justice can be done, however. Long ago I read an account in Time magazine of a NYC printer who printed a lot of brochures for the Soviet UN legation for the Soviet pavilion at the 1964 World’s Fair. The Soviets stiffed him on his fee, which was substantial, and didn’t pay him even after he got a state court judgment against them. Undeterred, he went and got a lien against the next Soviet-flagged ship to enter New York harbor. He went aboard with U.S. marshals, who impounded the ship, and within hours had a check for the full amount owed, with interest.
Diplomatic staff attend to the interests of the United States as an international sovereign entity.
Consular staff attend to the interests abroad of US citizens and companies. But US citizens and companies abroad are of course fully subject to the jurisdiction, laws, etc of the country in which they happen to be; being a US citizen doesn’t provide any kind of magic exemption or exclusion. So there’s a limit to what consular staff can do for you.
If you’re arrested by the Teapotistani authorities, the consular staff can visit you (because this is a right provided by the Vienna Convention on Consular Relations) to check on your welfare, and they can generally insist that Teapotistan should not treat you in a way that conflicts with the minimum standards required by international law (which are fairly minimal). They will use the welfare check to put you in touch with a local lawyer, if you want; paying the local lawyer is up to you. And of course they’ll report back to your family on how you are doing.
If you have gone to a trouble-spot and are, say, detained by, um, irregular forces, there is very little they can do. They will convey the interest the United States government has in your welfare to the government of the territory concerned, but usually not much more than that. They might do more - e.g. offering technical or military assistance to the relevant government - if what you are caught up in also affects the state interests of the US, but their focus there in not in benefitting you; it’s in protected the interests of the United States.
If you go to somewhere like the Gaza Strip, US law forbids US government employees from going there, so this severely limits what consular staff can do to assist you if you get in any kind of trouble. They’ll make some phone calls, basically.
I remember many years ago, when Britain was a bigger deal than today, the common wisdom for Canadians abroad was you were better off calling the British Embassy (as a commonwealth citizen, when that mattered) than calling the Canadian embassy. The Canadian embassies were famous for doing nothing for their citizens. (Although, to be fair, a decade ago they did supply questions to the Syrian torturers to ask Canadian citizen Maher Arar when the USA “renditioned” him to Syria… which cost the government $10M in the end.)
When things would go haywire, the Canadians like many western governments would organize mass evacuations of their citizens from new war zones - visiting/contract professionals, tourists, NGO’s etc.
Many Lebanese got Canadian citizenship (which, IIRC, takes just 3 years of residence). Many were refugees from the civil war in the late 70’s. When things settled down they returned to live in Lebanon, but with Canadian citizenship also. When things got very nasty again several years ago, many clamoured for the Canadian government to evacuate them although they had lived back “home” for decades. This cost the government millions of dollars.
As a result, the new rules basically say (If I remember them correctly) if you have dual citizenship with country Y and have lived primarily in that country for X years, the Canadian government will not make any effort to evacuate you. Plus, anyone evacuated will eventually have to pay for the cost of evacuation.
But to answer the OP, the general rule is “you broke it, you bought it”. Canada runs ads for tourists warning that things like drugs are treated very differently in other countries. (Maybe everyone should just be forced to watch “Midnight Run”). They might make an effort to intervene if they feel that the country is notoriously bad for human rights and the justice system is unfair - but they have no obligation to. Usually those notorious countries don’t need the aggravation of serious ill will from rich western countries, and you see many cases where eventually the citizen is expelled rather than sent to jail (with a “don’t come back” warning). But the embassy does not have to do anything…
State and local governments also enjoy sovereign immunity (though amendments to the federal constitution, notably the 14th, do permit suits against states in federal courts).