Link works although page was moved to another location

That is called canonical redirect.

And it’s done through redirect_canonical() which basically

Redirects incoming links to the proper URL based on the site url.

and

Will also attempt to find the correct link when a user enters a URL
that does not exist based on exact WordPress query.

(Those excerpts were both taken from the function’s reference.)

So in your case, although the post parent of A has changed from X to Y, the post A (or a post with that slug) still exists, and therefore, when you visit the old URL:

http://websitename/index.php/X/A/ (old URL - post parent is X)

with canonical redirect, you’d be redirected to the correct URL:

http://websitename/index.php/Y/A/ (new URL - post parent is Y)

and not being presented with a 404 (page not found) error page.

Try visiting http://websitename/index.php/A/ and you’d see the canonical redirect being applied.

And if you visit http://websitename/index.php/A123z/, assuming there are no post with A123z as the slug, then you’d see the 404 error page.

error code: 523