International law generally discourages countries from preventing people to leave, for example article 13 of the Universal Declaration of Human Rights:
Everyone has the right to leave any country, including his own, and to return to his country.
Or article 12 of the International Covenant on Civil and Political Rights
Everyone shall be free to leave any country, including his own.
Obviously, this is more a broad statement of intent than a legally binding and enforceable provision but the principle is clear. It is generally agreed that preventing someone from leaving should be limited to very specific situations (minors leaving without a guardian, decisions by the criminal justice system to keep someone in the country before a trial) and that broader restrictions on leaving are the hallmark of authoritarian regimes. In particular, the covenant on Civil and Political Rights was directed against Soviet-aligned countries, which had very restrictive policies on international travel.
Importantly, the fact that entry at the destination might be forbidden doesn't mean that leaving is itself forbidden from the perspective of the departure country. These rules are also a mess to enforce: Should the police know all the details of the law in neighbouring countries? Take decisions on behalf of all the countries one could fly to? It's much easier to let other countries (and transportation businesses) deal with their own rules and the people who want to go there.
In practice, there are however many examples of richer countries trying to deputise weaker poorer neighbours to “take care” of migrants for them but those efforts are often questionable from the perspective of international law and criticised as such. If and when this is formalised in a treaty or agreement of some sort, it would be ad hoc and bilateral.
More often than not, destination countries also specifically want to prevent the departure of people who do have a right to enter under international and national law (e.g. refugees), precisely because they had rather not have them there but have no clean legal way to refuse entry and send them back if they do make it to the border. By contrast, someone from a stable country with no believable claim to asylum who presents themselves to an airport is not such a big deal. They can be removed expeditiously and (relatively) easily. The dirty little secret in all this is that the people you want the least are those who have a bona fide claim to international protection, for it is not illegal for them to leave, enter through a border entry point nor even to cross an international border irregularly.