What countries banned it first? banned it last?
Sorry I can't answer exactly why so many countries made marijuana illegal, but how is pretty simple. The Single Convention on Narcotic Drugs treaty of 1961. 40 countries ratified it with most of the rest of the world consists of state parties.
This convention came up with the scheduled drug system, and outright placed cocaine, opium, and cannabis as Schedule I drugs. Psychotropic drugs such as LSD and MDMA were later added with the Convention on Psychotropic Substances in 1971.