Yes, sorry, the example is not as simple as Einstein would have advised. Yours is simpler. The rule is that every variable in the head must share with the body, so that the head can be ground as the body is ground. I make it more clear in the rest of the comment above, at least I hope :)
D = P(x,y) ← Q(x,z) % z is not shared with head(D)
throws me a bit, isn't it equivalent (as z is unused) to
D = P(x,y) ← Q(x)
which makes me wonder what y is doing. Would that leave y unbound, and if so is that why it's disallowed?
TIA