I have a Python script that creates a new user and configures it, I want this to be ran anytime a user SSHs into the server but the username isn't a valid one, how could I do this?
That is an incredibly bad idea. How would they learn what password you assigned? Consider how easy it would be to write a denial of service attack to log in as millions of unknown users. Hackers do that EVERY DAY to any public-facing server. Much better idea to have a web site where people register for a new username.
How to run a script if a user SSHs into an non-existent user?