First of all, you can't patent computer code, only inventions. The IP for code is copyright.
You always own the copyright in literary and artistic works (including computer code) unless they are "works for hire" (i.e. you are working for someone and creating it is your job). You can sell the copyright if you like in which case you have no further interest in it. Alternatively, you can licence it, in which case you still own the copyright (and can do whatever you want with it) while the licencees must follow the terms of the licence.
To know what you can do with a piece of code that is not yours you must read the licence and do what it says.
If you use MIT licenced software then, yes, derivative works can be "closed".
For the GNU General, if you are making a derivative work then you must distribute it under same licence so, yes, the code must be "open". However, if you write code from scratch and distribute it under GNU General you can still use that code as the basis for a "closed" project because its your code which you allow others to use.
In the comparison, the "same license" means the "same license" or one that grants equal rights, including but not limited to copyleft.