This is the most straightforward solution for the reported issue. If
there is a shape key active, read the coordinates from the PBVH instead
of from the SculptSession mesh array. This affects the cursor, the
dynamic mesh preview, and the tools.
The idea of the dynamic mesh preview was to show the original mesh while
sculpting on the modified. I don't think this makes much sense with shape
keys, so I disabled the preview there. The cursor and the vertex preview
should work correctly.
I'm not sure if it is worth adding an if statement to the sculpt_vertex_co_get function for a case that is barely used (andwhen it is, it is used with low poly meshes). That function is called
constantly multiple times per vertex and per redraw on high poly meshes,
so maybe this has a performance impact. Another solution could be
making a separate set of functions (something like
sculpt_vertex_modified_co_get ##) and use them just of the cursor and
the mesh preview.