I know that in Diffie Hellman, the final key (from Bob's point of view the final key is calculated as follows)
KB = (gx mod n)y mod n, wherex represents Alice's private no. y represents Bob's private no. g and n the two public nos.
which can be evaluated as
K = (gxy mod n) OR (gyx mod n), wherex represents Alice's private no. y represents Bob's private no. g and n the two public nos.
My question is that How does KB = (gx mod n)y mod n evaluates to K = (gxy mod n) OR (gyx mod n). Does the mod operator has a property where (gx mod n)y mod n evaluates to gxy mod n?
I think you have some misconceptions about what $\text{mod}$ means. Let $p$ be an integer, then the "object" $x\text{ mod }p$ is the equivalence class of $x$ in $\mathbb{Z}/p\mathbb{Z}$, that is to say the image of $x$ under the quotient map $$\mathbb{Z}\longrightarrow\mathbb{Z}/p\mathbb{Z},$$ which for simplicity we'll write $[x]$. It is easy to check that indeed $[x]^a = [x^a]$, which is the property you wanted.
Remark: all numbers considered here are integers.