I do not have a well-documented answer, so please take careful note that this is purely speculative.
The etymology of the first definition of enjoin, where you order someone to do something, is fairly straightforward and well-documented.
c. 1200, engoinen, "to prescribe, impose" (penance, etc.), from stem
of Old French enjoindre (12c.) "impose (on), inflict; subject to;
assign (to)," from Latin iniungere "to join, fasten, attach;"
figuratively "to inflict, to attack, impose," from in- "on" (see in-
(2)) + iungere "to join"
So the question is, how did it also become used to mean "to prohibit"?
Well, as noted Merriam Webster and other dictionaries, this meaning primarily refers to court orders. In this sense, "enjoin" and "injunction" are similar-- the courts enjoin you to do something or to refrain from something by issuing an injunction, and both words share the same root.
It is really just a game of semantics to determine whether an injunction is an order to do something or an order not to do something. For example, if a judge orders you to immediately stop using a trademarked logo, is he ordering you to stop doing something, or to start doing something? You'll have to immediately take action to cover/hide the logo from any storefronts or products you sell, alter your web page design, and so on.
Injunctions are very often orders to "not do" something, so it makes sense that it would pick up this connotation. If someone says "I got an injunction" it tends to conjure up the idea that they got a legal order for you to stop doing something immediately.
And any time an injunction is issued, you've been enjoined. Enjoined to do what? Well, very often, to stop doing what you're doing.