Prisoners lack the freedom to do what they want to. Free people have many activities other than work that they can spend their time on. When there are many enjoyable options, work isn't as appealing.
In regards to prisoners being locked in against their will, a country has the opposite problem of people being free to leave. An ambitious and hardworking prisoner has to work with the options within the prison until his sentence is up. If a citizen of a country has the drive to work and try to get rich, he's not necessarily going to stick around and support the UBI state.