Your rep() code produces the vector:
> rep(c(1,2,2,1),times=4)
[1] 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1
You can reference the elements in the vector c("x","y") by using their index, e.g:
> c("x","y")[1]
[1] "x"
provides the element at position 1 in your vector, which in this case is "x".
You can also reference this element multiple times by using a vector of indices, e.g:
> c("x","y")[c(1,1,1,1,1)]
[1] "x" "x" "x" "x" "x"
returns the element at position one in your vector 5 times.
So when you supply R with c("x","y")[rep(c(1,2,2,1), times=4)], which is the same as c("x","y")[c(1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1)], what you return is the same pattern, but are replacing those values with the elements in the vector at those indices.
So instead of returning 1,2,2,1 repeated 4 times, you are returning the 1st,2nd, 2nd, and 1st elements of your vector repeated 4 times.