Putting the rank = same; ...
statements in braces, e.g.:
digraph G {
rankdir = TB;
subgraph {
A -> B
A -> C
C -> D
X -> Y
// note that rank is used in the subgraph
{rank = same; A; X;}
{rank = same; B; D; Y;}
} /* closing subgraph */
}
… gives the desired result: