In Islam, the Quran does not forbid cannabis, however, the use of cannabis is deemed to be khamr (intoxicant) by many religious scholars, and therefore generally believed to be haraam (forbidden). However, some scholars state the meaning of khamr is fermented drink, not intoxicant, and in any event there is no toxicity associated with cannabis.
Although cannabis use in some societies in Islamic countries has been present, often but not exclusively in the lower classes,its use explicitly for spiritual purposes is most noted among the Sufi. An account of the origin of this:
According to one Arab legend, Haydar, the Persian founder of the religious order of Sufi, came across the cannabis plant while wandering in the Persian mountains. Usually a reserved and silent man, when he returned to his monastery after eating some cannabis leaves, his disciples were amazed at how talkative and animated (full of spirit) he seemed. After cajoling Haydar into telling them what he had done to make him feel so happy, his disciples went out into the mountains and tried the cannabis for themselves. So it was, according to the legend, the Sufis came to know the pleasures of hashish.
Source: Abdul-Rahman, Muhammad Saed (2003). Islam: Questions and Answers – Pedagogy Education and Upbringing. MSA Publication Limited. p. 123. ISBN 9781861792969.
Allah Is Great.