I would imagine that some programs have fraud protection of some sort. Imagine the hassle they have to go through if you happen to get scammed and the original owner, restores his access to the old affiliate accounts.
There will be so much drama about who has bought what, especially if you are accused to have hacked the accounts and not bought them.
To avoid such issues they simply forbid account transferring. I however wouldn’t call it ‘illegal’ as in against the law. Just prohibited most likely by the T&Cs of the given program. Otherwise why would people be risking to get accounts banned?