Its sort of like a custom.Its not really written down and there is no legal punishment, but if you disobey the custom you will in some way be shunned or punished by the people who follow that custom.
Originally, electors cast two ballots for president and whoever took second place in the tabulation became vice president. Starting in 1804, the president and vice president were elected on separate ballots as specified in the Twelfth Amendment to the United States Constitution which was adopted in that year.