What happens if I take a small piece of code (~400 lines) that is licensed under GPLv2, and modify and use it in my own project? Am I now obliged to license my program under GPL, or can I use a more permissive license like WTFPL, or do I have to license that particular file that has the GPL-ed code in GPL, and all other files in other license?
You are only allowed to use the code and distribute it and its derivatives under the GPL unless you have permission of all authors to re-license it. That is true for a part of the code, too: deleting one half does not make the remaining half magically something not derived from the whole. A license applies to each line of code unless it says otherwise explicitly.
Thus if you want to take part of a GPL-licensed project to incorporate it into your own, you become bound by the GPL as a whole, if you compile it into one binary or they work together closer than "at arm's length" (that is closer than two separate programmes talking to eachother over a well-defined public API).