Tensors are stored in memory as a single contiguous block of memory. It may be a straight line. Every tensor has two other components dimension and stride. Dim tells the size of the tensor in each dimension and stride tells the number of bytes you need to step in each dimension when traversing the array.
Reshape function will return a view i.e. in your case it would just change the dimension with the same underlying data (no change in bytes in memory and the same bytes are returned). Same is true for squeeze. Now when you run t[5]=5, it is changing the same underlying data that ‘t’ originally pointed to. For clarity the below code, gives the same output as yours.
def flatten(t):
    t = t.reshape(1, -1)
    t = t.squeeze()
    t[5] = 5
    return t

x = torch.ones(4,3)
flatten(x)
print(x)