There are huge logistical challenges with using large, securely contained sites like barracks.
For one, we don't have lots of sites like that in a usable condition sitting, well, unused. To bring an abandoned complex up to scratch is a huge outlay. Secondly, they tend to be surprisingly low-density accommodation given the size of the site and are therefore not very efficient. Thirdly, it is logistically more costly to supply and maintain these sites and they are not always easy to access for e.g. court visits.
The use of hotels has arisen because these buildings are in good condition, provide a high density of accommodation, are usually in central areas where it's easy to supply catering, security, get the residents to court, doctors appts etc, and because there have been an awful lot of hotels closing in recent years these buildings are quite commonly available on the open market and are cheap for what they are.