It is not "exceptionally unethical" as previously answered. Ethics has nothing to do with it as it is a matter of property. Just because a client pays you to develop a program for them does not automatically convey to them some ethical right of ownership to the work. After all it is the fruit of your labor. The property ownership is all that matters and that depends on the circumstances.
First, and this should go without saying, the only advice you should take seriously is that from an intellectual property lawyer in your jurisdiction. (I am not one.)
In the US, if you are the copyright owner of source code then you can license that work however you wish. You can sell it to Alice today and then give it to Bob tomorrow. You can license it to Acme Inc. as open source next week and then license it to Bell Corp. using a proprietary agreement next year. Being your property it is yours to dispense with as you see fit.
But you may have surrendered that right to the client. In my own independent contract work for software companies I have not yet seen a consulting agreement that did not explicitly convey the intellectual property ownership of my work to the client. In fact they are usually quite verbose on the matter and cast a wide net just to be sure with language such as "all rights, title, interests, secrets, etc" and then "in perpetuity". If you signed such an agreement with your client then you are bound by that and any attempt to resell the work later would be theft from the client and possibly fraud to the buyer.
However if you did not agree to such terms then the client does not necessarily have an implied ownership of your work. In the US for example you would need to refer to the appropriate state laws concerning work for hire and shop rights, again with the help of an IP lawyer. Much of it depends on precedence. Even if the client does have implied ownership you might find they don't care. Or they may be willing to sell you back the rights for reasonable compensation. (I have done that!) Get such indifference or deals in writing and then you will be able to freely market your work "guilt free".