You're right that the most likely cause is vibration and movement of the washer during the spin cycle. An unbalanced load will make the washer "buck", but even normal spinning has some vibration. Vibration is used in production environments to move things. It reduces friction and can offset gravity by making things bounce.
If one unit is sitting directly on top of the other, rather than on a separate, independently supported surface, it doesn't make a lot of difference whether the washer or dryer is on top. The vibration separates the two and causes movement. So basically, you need to either mechanically lock the two together, or put the top unit on a separate surface so the two units are mechanically isolated from each other.
From an ergonomics perspective, the washer on top is better (wet stuff is heavier and it's easier to let gravity help you get it into the dryer). But if the washer falls on your head, that's not so ergonomic. :-)
With a properly designed support system, you're better off with the washer on top. However, the washer is heavier, especially when full of water, which makes stacked units top-heavy. That creates additional requirements to prevent any risk of the stack falling over. If you don't have the background to properly design the support, or plans designed by an expert, put the dryer on top. The dryer is typically put on top because it is lighter and much less prone to movement, which greatly simplifies the requirements.
In any stacking arrangement, it's important to use a washer designed to minimize vibration and movement. These have features like built-in counterweights, unbalanced load detectors, etc.
If you have units designed to be stackable, that's your best bet. The manufacturer has already figured out what's needed to safely stack them.
You can make your own stacking arrangement. Typically, the designs involve the units sitting inside a substantial cabinet or framework that confines their movement, or the support for the upper unit has a lip to hold the unit in place, or the two units are fastened together.
Here are a few examples:
A little less elegant:
images courtesy Pinterest
Notice that these examples have the dryer on top.