A ghost writer is a craftsman who writes speeches or books for another person who gets the credit as author.
Although well paid, they’re called “ghosts” because they’re invisible.
In the fourteenth century, while there were warhorses and draft or workhorses, an ordinary rented riding horse was known as a “hackney” or a “hack.”
The word hack came to mean anything for hire, including writers who did commercial work of any kind to support their efforts at art.