Evolution of magnetism in topological insulators