It is not illegal per se. The consequence is you will not be owed the protections that registered ships flying a national flag will be. As you don't come under any jurisdiction, you can be approached and come under the extraterritorial jurisdiction of any other state.