This is what safety means. Safe is code verified by the compiler to be sound. Unsafe code is verified by the compiler and programmer together to be sound.
Sound code is code that will never exhibit undefined behavior when combined with any other sound code. A sound unsafe fn will never exhibit undefined behavior when combined with any sound code that upholds its requirements.
Undefined behavior is any code that has some runtime property that violates the Rust compiler's assumptions, which are here. Mainly: data races, incorrect pointer aliasing, writing read-only memory, reading uninitialized memory, and making invalid values.
So any unsafe code can be sound or unsound. Often people will use "unsound" and "undefined behavior" interchangeably, but you can understand "code with undefined behavior" to mean "code that when run (either run at all or run with certain inputs), will exhibit undefined behavior".