Is it legal, applicable to arm yachts, recreational vessels. For defense against piracy, thieves, terrorism.
Gun control laws
The moment you enter the 12 nautical miles zone of a country, you need to abide by its weapon laws. Most functioning large-caliber and fully-automatic weapons are not allowed in civilian hands globally. The moment the ship leaves the 12 nautical miles zone, the country law of its flag applies, so unless you happen to start in the US with a duly registered curio/relic deck gun with proper stamps... you'll have a hard time being allowed to have the thing on board in the first place, and entering any other country's water is pretty much violating their gun control laws and gun import laws.
Ship hulls don't support them.
That deck gun there is a type of Bofors 40mm L/60 twin mounting - 40x311mmR. That means, its installation weighs upwards of half a ton, as that's the smallest carriage setup according to Wikipedia. Navweapons helpfully provides gun weights of roundabout half a ton per gun. That puts the minimum weight at about that of a PAK 40, but as Navweapons tells us, a US Mark 1 Twin clocks in at 4.4 to 5.8 tons including guns. All on the one mounting spot.
With the bulk they are, no fiberglass ship hull could support that much load on the gun's small footprint. It needs a steel-hulled superyacht to even bear the deck load of such an installation. If your ship is the size of a coastguard or navy vessel, it probably is such a ship redesigned, a commercial fishing boat (similar specs), a cargo vessel, a large cruise vessel, or built to your specifications from the ground up.
There's no "somewhat akin" about it; it is an anti-aircraft mounted Bofors. Dec 24, 2022 at 13:23
1@TheDaleks Found the data... Navwqeapons for the resuce! I'm rather sure that's a USN Mk1 mounting or British Mk 5 mounting...– TrishDec 24, 2022 at 13:48
Yachts get a seat upgrade and chrome flash suppressors; and you have to reduce the number of hot tubs by one. Dec 25, 2022 at 1:00
@PhilSweet a Hot-Tub only weighs at best 2 tons filled with water.^^– TrishDec 25, 2022 at 1:15