We investigated the magnetic structure of HfMnSb2 and TiMnSb2 with first-principles calculations. We assumed ordered and disordered crystal structures for both compounds and investigated the transition of the magnetic structure. We theoretically confirmed that the helical magnetic order is stable in HfMnSb2, while the conical magnetic order was observed experimentally. Additionally, assuming a chemically ordered crystal structure in TiMnSb2 stabilizes the antiferromagnetic order. However, when the degree of order gradually decreases, the system exhibits spin-spiral density wave states and finally attains ferromagnetic order when the degree of order is 0. This trend is consistent with the experimentally measured results. We also found that the distortion of the lattice constants in TiMnSb2 compared to that of HfMnSb2 also plays an important role for the ferromagnetic order.