Hello Arun. Since this is happening only for a few users, I would first check whether Z is still a contributor to X’s profile. In NERM, when you manually change the profile owner, the previous owner becomes a contributor. This could explain why Z still has access.
Open X’s profile under Admin > Lifecycle > Profiles and check the Contributors and History tabs. If Z is an unintended contributor, remove that assignment. If Z still has access, check the Profile Access and disable workflow permissions across Z’s assigned user roles.
For future owner changes, I would use the Contributors workflow action instead of manually changing the owner, as this removes the previous owner automatically. Once corrected, check whether Y can still manage X’s profile and Z no longer can.