The Curve25519 paper gives you some hints about this. In Section3, it says:
Responsibilities of the user. The legitimate users are assumed to generate independent uniform
random secret keys. A user can, for example, generate 32 uniform
random bytes, clear bits 0, 1, 2 of the first byte, clear bit 7 of the
last byte, and set bit 6 of the last byte.
Curve25519 lets you use as secret key any 32-byte sequence that fulfills this restrictions. Although in principle multiplication assumes that you introduce a valid secret key fulfilling all these conditions, the code you mention tries to enforce this on its own. Note that it doesn't perform a validation check on the secret key, but directly modify it in case it didn't comply.
So, clearing bits 0, 1, and 2 of the first byte is this line of code:
mysecret.bytes &= 0xf8
Clearing bit 7 of the last byte is this one:
mysecret.bytes &= 0x7f,
And setting bit 6 of the last one is the next line:
mysecret.bytes |= 0x40;
With respect to your last question, I think there may be a misunderstanding. In the comments, you seem to be asking about commutativity of Curve25519 (i.e., $ab == ba$), rather than associativity. Remember that you are performing scalar multiplication. That is, the multiplication of a scalar $x$ by a base point $G$. In this case, the scalar is the secret key. Therefore, it doesn't make sense to think of commutativity.