That entirely depends on countries X and Z.
If country X discriminates against citizens of Z, then not telling that you are citizen of Z might have all kinds of negative consequences for you when found out.
If you are asked a direct question you have the choice to refuse an answer (which usually means your visa application is refused, or you are refused entry), you say the truth, or you lie which is usually worse than telling the truth if found out.