Do not rub it on a person’s skin… (Exodus 30:32)
Again, “messiah” literally means an anointed person. This mitzvah prohibits anointing anyone other than the designated individuals: the High Priest, a king of the Davidic dynasty and a third person we didn’t mention in the previous mitzvah, the kohein m’shuach milchama (“priest anointed for battle”), whom we’ll meet in Mitzvah #526.
If one intentionally anointed himself with the shemen hamishcha, he would be subject to the penalty of kareis (spiritual excision). If he was smeared with it unawares, he was to bring a korban chatas (sin offering).
The principle behind this mitzvah is that the anointing oil is unique and is to be used only for special purposes. If everyone could use it, it wouldn’t be special for the Temple, which would lower the esteem of God’s sanctuary.
Now’s as good a time as any to mention that not even every king of the Davidic dynasty was anointed with the shemen hamishcha, since the position was hereditary. It was really only employed when the succession was contested. (See Talmud Kerisos 5b and also Horayos 11b.)
The prohibition against anointing an improper person with the special oil applies to both men and women whenever the shemen hamishcha happens to exist. It is discussed in the Talmudic tractates of Kerisos and Horayos, as noted above. It is codified in the Mishneh Torah in the first chapter of Hilchos Klei HaMikdash and it is #84 of the 365 negative mitzvos in the Rambam’s Sefer HaMitzvos.