When you include a header file like sys/stat.h you can use the functions
like stat. But where is the function body? I didnt write the body, yet it still does something.

But where is the function body?

In an object library somewhere, either statically or dynamically linked to your code when you build. Many libraries are linked for you by default, such as the standard C library and common POSIX libraries (which includes the things declared in sys/stat.h). Others will need to be linked explicitly in your build command or make file.