The reason is that expand does not allocate more memory but just make the tensor look as if you expanded it.
You should call .clone() on the resulting tensor if you plan on modifying it to avoid such behaviours.