It’s worthwhile to search out a few videos of Coast Guard Motor Life Boats which are designed to go through waves like this without staying capsized.
In most vessels* the center of mass is ABOVE the center of buoyancy. At some level, they WANT to capsize, but when they heel to one side, the center of buoyancy shifts (because more of the boat on one side is under water, and therefore providing buoyancy) and provides a righting moment.
*other than the aforementioned motor life boats and submarines.