People, who enter a country without the proper documents, are "illegal aliens," and depending on the country, can be jailed (sometimes for years), fined, deported, and/or prohibited from ever entering that country, again, for any reason.
Most countries (such as the USA, China, Japan, Mexico, Russia, South American, Middle Eastern and European countries) have " immigration and visa laws," and a person from a foreign country has to apply for and receive permission to "legally" immigrate, or apply for a visa to enter that country for such purposes work, study, or business and personal reasons. These laws are in place and enforced to protect the safety and wellbeing of its citizens, which is one of the primary duties of government.
Someone else can probably explain this better than I did, and I hope I didn't make too many mistakes.