My santa cruz heckler ghost shifts from frame flex. Is there anything I can do?
Given that the cassette is tied to the axle, if the alignment is changing, you have a few possible causes:


Freewheel is worn out and has a significant wobble
The pivot where the chainstay and frame connect is worn and loose
Axle itself is loose, either through the hub, or at the dropouts


When applying pressure to the pedal with the brake on, it will naturally pull the alignment of the axle so that drive side is further forward than the non-drive side.  You also mentioned that the whole wheel moves, so I would lean towards a pivot or axle problem.