Not all of the purposes of sanctions are straight forward in terms of causing policy change in the target government.
Another really important purpose of sanctions is to provide an option to countries displeased with the conduct of a fellow sovereign nation to express displeasure with its policies without escalating the dispute between the nations to war.
Often it is politically necessary domestically, and in terms of communicating diplomatically with another nation to not simply do nothing in reaction to clear misconduct. Sanctions are, by definition, pretty much all of the intermediate options between doing nothing and going to war.
Even if the usual alternative to sanctions would be doing nothing, sometimes the alternative to sanctions would be war, and by providing a relief valve other than war, sanctions can still leave the parties better off even if they don't cause the policy changes which officially justify the sanctions.
Furthermore, often sanctions operate on multiple levels and work in concert with domestic political forces.
For example, sanctions on South Africa due to apartheid didn't end that system all by itself, but they probably did strengthen the position of apartheid opponents within the South African political system, and probably hurt its supporters - sometimes by means as simple as serving as a means of public shame imposed on South Africans who were traveling abroad.
Also some sanctions can be more effective than others.
For example, Mexico's response to changes in U.S. policies towards it by choosing to trade in agricultural products with countries other than the U.S. absolutely hurts U.S. farmers in a way that encourages them to urge moderation on the part of a regime that they helped put in place.
Even in a totalitarian regime, governments can't maintain their power and authority without somebody in the country who supports them, and indeed, not just one faction that supports them, but many factions that support or at least tolerate the current regime. The fact that a country does not have elections does not mean that it does not have politics that drive decision makers to make particular policy choices.
Really effective sanctions need to accurately identify points where sanctions can squeeze people and factions who can influence the policies of the current regime, whether it is totalitarian or democratic, which is something that has to be determined on a case by case basis in either situation. The sanctions that might persuade a Trump administration to act differently might very well be different than those that would have persuaded an Obama administration to act differently. Sanctions that might be effective with a totalitarian regime in Egypt might be different than those that are effective with a totalitarian regime in North Korea.
Devising sanctions is more art than science and doing it well requires an accurate understanding of the de facto power brokers with a particular ruling group at a particular time.