That's basically what Australia does: They pay the governments of many of the smaller micronation islands and island nations to have detention centers set up, and if you're caught trying to illegally come to Australia in a boat, you're not rescued and brought to shore like our (UK) shitty border control and RNLI but dumped in one of these centers until you're processed.
And processing can take months, and in the meantime they live in conditions not out of place of a third-world shithole (cramped rooms, bad food, no entertainment, et cetera).
When Australia implemented this "inhumane" coughlaughcough policy, the sheer amount of illegal migration attempts plummeted to single digit levels; when they temporarily tried stopping these policies, it shot right back up again.
Gee, I wonder why?