Honeycomb or triangular lattices were extensively studied and thought to be proper platforms for realizing the quantum anomalous Hall effect (QAHE), where magnetism is usually caused by d orbitals of transition metals. Here we propose that a square lattice can host three magnetic topological states, including the fully spin-polarized nodal loop semimetal, QAHE and the topologically trivial ferromagnetic semiconductor, in terms of the symmetry and k · p model analyses that are material independent. A phase diagram is presented. We further show that the above three magnetic topological states can indeed be implemented in the two-dimensional (2D) materials ScLiCl5, LiScZ5 (Z=Cl, Br) and ScLiBr5, respectively. The ferromagnetism in these 2D materials is microscopically revealed from p electrons of halogen atoms. This present study opens a door to explore the exotic topological states as well as quantum magnetism from p-orbital electrons by means of the material-independent approach.