We used to have something similar on a prior boat with a foam mattress. I finally figured it was moisture given off by our bodies getting wicked to the bottom of the mattress, which sat on a 'cold' surface. My inexpensive, but immediately effective, fix was to cut some large cardboard boxes and lay the cardboard flat under the mattress. This provided sufficient 'insulation', so the bottom of the mattress no longer sat on a cold surface.
FWIW my other half has re-covered numerous foam mattresses from boats of similar construction (same boat builder), and they always had mildew on the underside.