We provide experimental evidence for confinement of water molecules in the pores of hexagonal structure of YPO4 at elevated temperatures upto 600 K using powder neutron diffraction. In order to avoid the large incoherent scattering from the hydrogen, deuterated samples of doped YPO4:Ce-Eu were used for diffraction measurements. The presence of water molecules in the triangular and hexagonal pores in the hexagonal structure was established by detailed simulation of the diffraction pattern and Rietveld refinement of the experimental data. It was observed that the presence of water leads specifically to suppression of the intensity of a peak around Q = 1.04 {\AA}-1while the intensity of peaks around Q=1.83{\AA}-1 is enhanced in the neutron diffraction pattern. We estimate the number of water molecules as 2.36 (6) per formula units at 300 K and the sizes of the hexagonal and triangular pores as7.2 (1) {\AA} and 4.5 (1) {\AA}, respectively. With increase in temperature, the water content in both the pores decreases above 450 K and vanishes around 600 K. Analysis of the powder diffraction data reveals that the hexagonal structure with the pores persist up to 1273 K, and transforms to another structure at 1323 K. The high temperature phase is not found to have the zircon or the monazite type structure, but a monoclinic structure (space group P2/m) with lattice parameters am= 6.826 (4) {\AA}, bm= 6.645 (4) {\AA}, cm= 10.435 (9){\AA}, and \b{eta}= 107.21 (6)°. The monoclinic structure has about 14 % smaller volume than the hexagonal structure which essentially reflects the collapse of the pores. The phase transition and the change in the volume are also confirmed by x-ray diffraction measurements. The hexagonal to the monoclinic phase transition is found to be irreversible on cooling to room temperature.