I find that this would be very useful in certain situations in which I want to install software in a different way, or change flags, or not let the software manager know the program has been installed (so it wouldn't look for updates). I know packages can be built from source codes, and this is relatively common, but I don't know about the other way around. It would also be useful for converting one type of package into another when Alien doesn't work or doesn't provide good results. I've been searching on-line but there seems to be no or few records of source code extraction from pre-built packages...
Debian and RPM packages don't contain source code, only the compiled result. However, you can fetch the source packages - SRPMS, or the Debian description, patch, and original tarball.
Those can be recompiled with whatever local modifications you want, and will more or less do what you want - though remember to adjust the version number to make it clear that your version is "later" than the distribution version.