By law you have the sole rights to any of your own creative works. This include code written by you.
No-one has any right to demand you to license your work under any license they want. Instead, you have the freedom to choose any license for your work yourself.
If you combine your code with code licensed under the GPLv2 then you are obligated to release only the source code of said code but not yours. Licensing the end product is tricky because you only hold the copyright to your own code but at the same time no one can force you the terms of your license for your code. So basically you have to explain this to the end-user that there are two separate codes with different licenses (one with the GPLv2 and other with MIT) and not one code with either license. This myth like Gnu licenses somehow "infect" code is outright lie. The law protects you and your rights. Even if you have contributed to any project under the Gnu license you still have the right to demand that your contributions would be removed from the project if one day you choose so. Because only you have the copyright to your code and no license can ever take that away from you. This is actually the biggest legal problem (but not the only one) of restrictive copyleft licenses. Because with permissive open source licenses both the contributor and the "project manager"/"Copyright holder of the initial code" have the same rights (but no obligations) therefore there would be no reason for anyone ever to withdraw their code.
Many people fail to understand that there is no contract or license that can take away your right given by law. The same way for example, if child labour and slavery are banned by law then even if someone manages to contract a minor or sells themself into bondage than such contracts are legally void. Not only that but the other side to sign such contracts gets punished by the law.