Sifrei Mitzvot sur L’Exode 22:27

אֱלֹהִ֖ים לֹ֣א תְקַלֵּ֑ל וְנָשִׂ֥יא בְעַמְּךָ֖ לֹ֥א תָאֹֽר׃

"N’outrage point l’autorité suprême et ne maudis point le chef de ton peuple.

Mishneh Torah, Foreign Worship and Customs of the Nations

Whosoever admits idolatry as truth, although he be not a worshiper thereof, behold him, he is shaming and blaspheming the Glorified and Awful Name. The idolater's corpse is, therefore hung, even as that of the blasphemer's, and both offenses are punishable by stoning. It is even for this reason that I included the law of the blasphemer in the treatise concerning idolatry, for both of them deny the source of everything.7Keritot, 3b; Sanhedrin, 45b.

Tur

It is forbidden to curse a judge, and one who curses him transgresses a negative commandment, as it is said, "You shall not curse the gods." Anyone who curses one of Israel transgresses a negative commandment, as it is said, "You shall not curse the deaf." And the Torah specifies the case of the deaf person to teach us that even though he does not hear and is not pained, all the more so one who hears and is pained by the curse incurs lashes for it. Maimonides wrote that one who curses a sleeping person is liable, since he is no different from a deaf person.

Tur

One who curses the dead is exempt.