Form compiles differently inside vs outside time loop [3D elasticity]

That is not suprising as you would like these values to update.
What I meant is that you should not redefine dx, ds and boundaries. You should instead change the values of the already existing object boundaries and dom_marker.
Note that you would have to update the BCs, as mentioned in

I am going to give you a simple example, where the markers are updated, without the form and measure being re-defined

from dolfin import *

mesh = UnitSquareMesh(32, 32)

boundaries = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 0)
ds_c = Measure("ds", domain=mesh, subdomain_data=boundaries)
L = 0.8
marker = CompiledSubDomain("on_boundary && x[0]<L", L=L)
marker.mark(boundaries, 1)
form = 1*ds_c(1)


print(f"L={marker.get_property('L')}, val: {assemble(form)}")

for i in [0.1, 0.2, 0.4, 0.8]:
    marker.set_property("L", i)
    boundaries.set_all(0)

    marker.mark(boundaries, 1)
    print(f"L={marker.get_property('L')}, val: {assemble(form)}")

gives

fenics@dokken-XPS-9320:/root/shared$ python3 mwe.py 
L=0.8, val: 2.5625
L=0.1, val: 1.1875
L=0.2, val: 1.375
L=0.4, val: 1.75
L=0.8, val: 2.5625