How to impose spatially varying dirichletbc boundary conditions for one direction in a linear elasticity problem?

This is because the last keyword argument V is only used when you collapse a function into a sub space. Then you send in two arguments in locate_dofs_topological, then uncollapsed and collapsed subspace. This returns you two arrays of degrees of freedom in each of these spaces.

Since the collapsed function has no direct relationship to its parent object, one supplied the subspace to ensure that the BCs are imposed on the correct part of the variational form