Dormitory ship

A dormitory ship is a vessel which provides as its primary function floating living quarters. Such craft serve as conventional land-based dormitories in all respects except that the living quarters are aboard a floating vessel, most often moored in place near its host facility. It may be seaworthy or not.
Dormitory ships, regardless of their original design or function, may serve as temporary or permanent housing for refugees, accommodation for academic institutions, and off-shore oil drilling operations. 
When a vessel is used by the military for dedicated housing, as at shipyards,
naval bases, and afloat abroad, it is known as a barracks ship.
An analogue to both is the prison ship, which provides a floating space for incarceration, possibly referred to as a brig in the military.
A vessel that contains living quarters as ancillary support to its primary function — such as providing hands-on maritime training at sea — is more appropriately categorized as a training ship.
In 2016 what had once been the world's largest cruiseferry, "Ocean Gala", was chosen by the Swedish migration bureau to become temporary housing for some 1,800 of that nation's estimated 160,000 refugees which had arrived in Sweden in just the prior year seeking asylum there. This proposal did not come to fruition.