Fiqh-us-Sunnah Volume 4, Funerals and Dhikr, Fiqh 4.074.
The author of al-Mughni said: “If a person died while in a ship on the sea, then, according to Ahmad, they should wait a day or two to find a place to bury him, unless they are afraid that the corpse would decay. If they cannot find a place (on land) to bury him, then the deceased should be washed, shrouded, a funeral prayer offered for him, then tied with a heavy weight, it be thrown into the water.” This is the opinion of ‘Ata and Al-Hasan. Al-Hasan said, “He is to be put in a basket and then thrown into the sea.” Ash-Shafi’i said: “The body should be placed on two boards and let into the sea so that the boards might take it ashore, where some people might find it and bury it. But if one throws it into the sea, one would not be committing any sin.”
The latter, i.e. burial at sea, is preferable, because it serves the purpose of covering the body which is comparable to burying him. Tying it between two boards is apt to expose it and cause it to be disfigured and mutilated. It might be thrown on the shore, mutilated and naked, or it might fall into the hands of pagans. That is why we believe the second course mentioned above is to be preferred.