The compositional structure of indefinite causal order