The phylum tardigrada is a member of the panarthropods, a group that includes the arthropods, tardigrades, and onychophorans, which are all legged ecdysozoans. If I remembered it correctly, such classification arose before molecular evidence, but recent analysis of DNA sequences does support the panarthropods forming a monophyletic group.
Regarding the evolution of the tardigrades, a very recent paper (published just last month) provided some new insights. The paper investigated into the Hox genes (genes controlling body plan) of the three panarthropod groups. It turns out that the tardigrades lost a whole segment of their body. The majority of the segments in tardigrades are analogous to the head segments of the arthropods. This probably lead to the compact body structure seen in tardigrades today.