To prevent smuggling/illegal travel of people.
In developing/poor countries it is necessary so that it adds another layer of checking and compliance with visa/immigration procedures.
In case airline employees have been bribed or compromised, another authority is there to check passports. They also have necessary experienced personnel and machines to detect fake passports and/or visas. Which perhaps airline employees would not as many are private.
Having an immigration control means having Govt control, because such officials are many times reporting to some Ministry such as Interior, Foreign or Defense, etc.
Makes running away from the country a little harder too, rather than lax/free control where its all on the airline. If airline cuts corners, it would get ...... very quickly.
This is more a problem in 3rd world developing/poor countries.......