It may or may not technically be 'illegal' to have someone else mail it to you out-of-country (I'll let others sift through the laws) but you are taking a whole bunch of unnecessary risk if you do and I don't understand why. However, we know for certain that "It’s against the law to give false or misleading information in your application".@Harkiran1997
Can you point the section of the criminal code where it says it is illegal to mail a work permit outside Canada? Here, I will link the criminal code for your convenience: https://www.laws-lois.justice.gc.ca/eng/acts/C-46/index.html
If a government agency (IRCC, CRA etc.) says something is illegal, they have to derive power from the laws made by parliament, they can not just arbitrarily make something legal or illegal. If they do, these rules can be refuted in the court.
Generally, the rule or policy about not mailing outside of Canada is designed to make the process more secure (for Canadians, IRCC & applicants) and protect against all kinds of the complications associated with verifying identity for security purposes, lost mail or claims of lost mail, mail theft in foreign country, a whole raft of fraud against against the Canadian immigration system and fraud/scams against applicants themselves (for example, pay me and I'll mail you your permit, etc.) and the ability to check identity and have at least some confidence that these documents are going to the right person. This is why work permits are mailed to your Canadian address (you've already been verified at a port of entry so there has been at least one check that you are who you say you are), or if you are outside of Canada, they are issued by the CBSA at port of entry who will first verify your identity. This goes for PR cards too -- "We don’t send PR cards to non-Canadian addresses and we don’t allow third parties to get them for you."
Someone in Canada could mail you your work permit but why? "Your permit (study or work) is not a visa and doesn't allow you to travel back to Canada." A work permit alone doesn't allow you to re-enter the country so why can't it just wait for you in Canada at your home? Why would you take the risk of having someone mail it to you and losing it in the mail? Best wishes!