No, XYZ will not get the exemption if he purchases the house in his relatives’ name. Moreover, there is clubbing provision of income u/s 64 of the I T Act. In case , those relatives gives the house on rent, the income shall be taxable in the hand of XYZ by virtue of section 64 of the I T Act. You should read more about clubbing in another question answered by me .Here

Hi,
I understand that since XYZ hasn’t yet bought the house for claiming exemption, he may be advised to purchase the house in his name only. Clubbing provisions will also be attracted undoubtedly if the house were to be purchased in the name of wife/DIL.
I also understand that the exemption granted u/s 54 can be
revoked if the assessee transfers the new house within 3 years of
purchase/construction; a lock-in period of 3 years has to be
observed. Now suppose the assessee had duly purchased the house in
his exclusive name only and claimed exemption u/s 54 on the full amount. But before the expiry of 3 years, he transfers this house to his wife. Would exemption earlier granted u/s 54 be withdrawn? The answer is: Yes.
But, there’s a judgement relevant to our case, though it’s
been rendered in the context of allowance of exemption u/s 54 on a
block of four flats rather than “a” flat.
In the case of K.G. Vyas v. ITO [1986] 16 ITD 195 (Bom.), all the
four flats were purchased by the assessee in the same building for
the purpose of his own residence and were being used by him for that
purpose only. The mere fact that the assessee had purchased them
jointly either in the name of his wife or in the names of his sons
would not materially affect or alter the factual position that he
was the owner of all the four flats and that he was also living in them along with the members of his family. The fact that on a future date, the assessee may divide these properties among the members of his family was of no relevance or consequence for the purpose of allowing relief to the assessee under section 54, since the assessee had fulfilled the conditions laid down under section 54, namely, that he had purchased a house for his own residence by investing the sale proceeds of his former residential house in the purchase of these four flats. It could hardly be denied that considering the strength of the assessee’s family with ten members, the accommodation acquired by the assessee in the form of four flats in
the same building was commensurate to his requirements. The assessee
was, therefore, entitled to full relief under section 54 in respect
of the entire amount invested by him in the purchase of four flats
for the purpose of his own residence under section 54(1), and for said reason, all the four flats should be regarded as a house of the appellant and not as separate houses. Shiv Narain Chaudhari v. CWT
[1977] 108 ITR 104 (All.), B.B. Sarkar v. CIT [1981] 132 ITR 150/7
Taxman 239 (Cal.) and CIT v. Kodandas Chanchlomal [1985] 155 ITR
273/23 Taxman 579 (Guj.) relied on.
The word `assessee’ in section 54 must be given a wide and liberal
interpretation as to include his legal heirs also – Mir Gulam Ali
Khan v. CIT [1986] 28 Taxman 572 (AP).
In my view, the thrust of the underlying requirement of Section 54 is that the money received as sale proceeds from the disposal of old house should be invested in a new residential house within the requisite time. The fact that the assessee has got the property registered in the joint names of himself and his wife would not in my opinion militate against the provisions of Section 54 if interpreted constructively and in the right spirit.
Thanks.