tl;dr summary: the technique for dealing with rough seas is to not deal with rough seas.
We often see ships destroyed by storms and waves as tall as dozens of meters, so how does SpaceX keep these floating landing pads stable so it remains level during the landing?
They don't launch when there are storms and waves as tall as dozens of meters. Just like all other rockets, Falcon 9 has weather constraints when it is allowed to launch or not allowed to launch. But unlike most other rockets, these weather constraints do not only apply to the launch site but also to the recovery site. (The Space Shuttle had sea state constraints for booster recovery.) In other words, weather at the recovery site is a launch commit criterion just as much as weather at the launch site.
Very early in the recovery program, when they weren't as successful as they are now, they also simply canceled the recovery. This happened, for example, with Hispasat 30W-6 on 2018-03-06, where the ASDS was left in port because of bad weather. The booster executed its maneuvers, but did not attempt even a simulated landing, and crashed into the sea.
However, nowadays, it is the other way around: if the recovery is not possible, the launch is postponed. SpaceX has mentioned this several times on Twitter using phrasing like "standing down due to recovery weather". This has some interesting implications, especially for short-duration free-flying crew missions like Inspiration4: you need to have good weather in 4 different places:
- Launch weather for the Falcon 9 at the Cape.
- Recovery weather for the Falcon 9 700 km downrange at sea.
- Recovery weather for the Dragon in case of an in-flight abort at all the required recovery sites (including e.g. the Cape and Ireland).
- Recovery weather 3–5 days from the launch for the return at at least two recovery sites. (While a Dragon which is docked to the ISS can easily delay its return by multiple days or even weeks, and you only need to predict the weather about 1 day ahead, for a free-flying mission you can really only delay by one day or so, and you need to already predict the weather 3–5 days ahead before you commit to launch.)
For Starlink launches out of the Cape in the Winter, when there are often storms and high seas in the North, SpaceX launches to the Southeast instead of Northeast, even though this requires more propellant and thus can launch fewer satellites.
What if stormy weather hits after the launch?
Again, normally SpaceX wouldn't launch if the weather forecast was not favorable for the recovery. Or, they will re-route the drone ship around the weather, or temporarily take shelter in a different port.
Also, the booster is secured to the deck. In the beginning, recovery crews would board the ASDS and literally weld the landing legs to the deck. Today, they have the Octagrabber robot which attaches to grab points at the bottom of the rocket and thus lowers the center of mass, since it is very low to the ground and very heavy.
However, it has happened a couple of times that the drone ship hit rough seas that were not forecast and could not be routed around, and the result was that the booster fell off the deck and was lost at sea or was severely damaged:
Arabsat-6A: The Falcon Heavy center core successfully landed on the ASDS Of Course I Still Love You. However, the Octagrabber had not been modified to be able to attach to a Falcon Heavy center core, so there was nothing securing the rocket to the drone ship. When the drone ship hit rough seas, the center core fell overboard and was lost at sea.
Thaicom 8: A radar glitch led to a hard landing causing damage to the landing legs. Because of this damage, the legs couldn't be properly secured:
Crew-1: Booster B1061-1 landed close the middle of the ASDS:
But when it returned to port, it had slid around on the deck, leaned heavily to one side, showed multiple damaged engines, and had almost broken through the railing: