Khamenei, one of the most consequential figures in Iran over the past half a century, built a theocratic system that stayed loyal to him