Just like we don't let people who come to the Emergency Room die because they can't pay, we, as a society, can take care of the few people who, for reasons like mental health, or physical ailment, can't work.
currently those that can't find work (even if they are capable) are getting social welfare.
all UBI is doing is that this welfare is given to everyone unconditionally. so the benefit does not go to those that can't find work but also to those that do find work. who then have the freedom to take breaks (when they have kids for example) because they are covered by UBI. and at the same time free up space for someone else who wants to work but can't find work.
Not all of them of course - we have social systems. But those are far from a silver bullet.