(Image source: elizabethdavenport)

This idiom derives from the time when people travelled by horse and cart and there was a predetermined order in which they travelled. You could not put a horse before a cart because the horse was necessary to pull the cart. From the 1500s on, numerous English writers like Sir Thomas More, William Shakespeare and Charles Kingsley used this phrase, which also appears in Greek, Latin, French, German, and Italian. In English, it was a cliché by the 1700s.