After enjoining us not to curse God, nor the judges, the Torah now tells us not to curse a leader of the nation. This includes both the king and the head of the Sanhedrin. (A comparable example in American society would be the President, who is the Chief Executive, and the Chief Justice of the Supreme Court. The President may be the highest office in the land, but there’s more than one branch of government.) Accordingly, it is forbidden to curse both a political leader of the people and a religious leader of the people.
The reason for this mitzvah is that a civilized society necessitates a system wherein someone takes charge. This person will make many judgment calls in his capacity as leader. Not all of them will be popular. Some of them will be errors in judgment. Nevertheless, this is a preferable system to having no one in charge, as in-fighting will lead to perpetual deadlocks and a constant state of impasse wherein nothing ever gets done. Since this person fills such a crucial role in society, his honor must not be treated lightly and it is inappropriate to curse him even when one disagrees with his policies. This is true behind his back and even more so to his face.
This mitzvah applies to both men and women, at a time when the Jews reside in Israel with a king and/or a Sanhedrin. In the Talmud, this mitzvah is found in tractate Sanhedrin, page 66a. In the Mishneh Torah, it is found in Hilchos Sanhedrin, chapter 26. It is #316 of the 365 negative mitzvos in the Rambam’s Sefer HaMitzvos.