Structural and magnetic configurations of Co/Mn ions, the most widely studied transition metal dopants in ZnO-based dilute magnetic semiconductors, have been investigated using first-principles density functional calculations. The study provides a fundamental theoretical understanding on the distribution of the magnetic ions in the ZnO host and its corresponding magnetism. Results show that the substituent magnetic ions at the Zn site strongly tend to aggregate chain-like via oxygen on the ab plane with an antiferromagnetic coupling in contrast to paramagnetic isolated free Co/Mn. Substitutional Cu codoping is found theoretically to reduce the magnetic dopant's tendency towards chain-like aggregation, in good agreement with recent experimental observations.