Hello,
For that you just need to understand the transistor level schematic of CMOS.
And along with that, just understand the PMOS transistor and NMOS transistor working.
after understanding the schematic level, you will get the answer of your question.
if you go through the operation of the elements in the design you can easily understand why it is working like. it is because of the opposite elements used in the design (pmos,nmos)