In older forms of Iberian languages, the norm was to employ enclitic pronouns with all verb forms, but with an exception: certain classes of words would draw the pronoun(s) to the front causing proclisis (these are called attractors, to borrow the Portuguese terminology)
While the classes varied from language to language, one universal was negative adverbs. Thus you'd have compráronnoslos but no nos lo compraron. Eventually in Spanish, for whatever reason, the proclitic position became the default. Commands, for some reason, were the exception, still using enclisis (hence vete or envíenmelo)... except in the negative which obliged proclisis.
As a result, the commands in Spanish (and, afaik, all the Iberian languages regardless the default position elsewhere) use enclitic pronouns for affirmative commands, and proclitic pronouns for negative ones.