What are the purposes of *.pyd files in the DLLs directory, header files (*.h) in the include directory, and *.lib files in the libs directory? When I delete them it seems that at least some basic python code works properly.
*.pyd are compiled python extensions (on windows). *.lib are library modules used for building and linking with python itself. The *.h are C include files needed when you are creating your own extensions.
Generally these are all quite small and do not consume material disk space. I recommend you leave them alone. even if you don't need them now, you may want them in the future (when it might be difficult to locate).
Purposes of different files in python installation