Copying code into something you're doing is legally creating a derivative work, so you must abide by the license requirements. All open source/free software licenses I've looked at demand that attribution be kept, so it's not just a question of etiquette.
If you have a list of credits somewhere, you should make sure the licensor is in that list. If it's in its own separate section (either its own file or a piece of a larger one), it'd be good to flag that and (of course) attribute it.
If it's refactored beyond recognition, it's still a derivative work, and you're still using somebody else's code, so legally and morally you must give credit.
You must of course abide by all other restrictions. You mentioned the GPL; in this case, the whole product must be redistributed under the GPL, or not redistributed at all. It doesn't matter whether the code is refactored beyond recognition and split up among files, as long as you directly used the code in your code. Different parts of the code may of course be under additional licenses, as long as they're GPL-compatible, but you must abide by the requirements of the GPL to redistribute.