When the input X and Y= +5V, then both the diodes D1 and D2 are OFF.
The transistor Q1 gets enough base drive from the supply through resistor and therefore transistor Q1 is ON and the output Z=Vce(sat) corresponds to 0V.
Similarly when inputs either x=0V or Y=0V or when both inputs are equal to 0V, at that time the transistor Q1 is OFF and therefore, output voltage Z= +5V.
Enjoy...😎