Let’s say I’m a Canadian working in the US under TN. Is it possible for me to do freelance work and receive compensations into my Canadian bank/Canadian PayPal account? If not possible, how would the IRS/government know about this?
Not legally, unless you perform the work outside the US or have a permit to work for your clients.
Yes but you need a second TN for your freelance work. You can have multiple TNs at the same time.
In answer to how would they know, PayPal and your Canadian bank would tell them.
Read up on FATCA and FBAR reporting requirements
What if a Canadian works full-time in US under TN visa, and in the mean time doing freelance work for a Canadian company and get paid directly via a Canadian bank account?
Illegal unless the Canadian has as TN to conver that extra work. The problem is the work is being performed in the US. You could do something like run an online store in Canada via Amazon provided you drive up to Vancouver now and then to do any actual work for it, such as ordering new inventory, shipping stuff to Amazon, etc., and collect the income passively while in thy US (still gotta pay IRS). You can't do WORK in thy US without a work authorization. You can have multiple TN's and have one that authorized your side business though. Then you're good.
Can not tell about TN, on H1B the answer is clear no, only royalty and passive income like dividends. Soyiu can write a book or invent something, but no direct labor selling
So how would IRS/government know about this if the transactions are done outside of the US?
Even more, if you report to IRS and pay taxes, they don’t report it to USCIS. But all options are clear felony which would probably bite you sooner or later. Why would you risk?