A compiler is a function from source code strings to binary bytes. Writing out instructions to do memory-unsafe things is not in itself a memory-unsafe activity.
I believe the main reason is for achieving the best possible performance. Someone closer to the compiler could give more detail.