The answer to why the standard library is 'allowed' to return by reference is, that it does not allocate anything on the stack. It returns references to already allocated memory which lives long enough.
So you have basically two choices:
If you allocate memory on the stack you have to return it as value.
This includes the Box<_> scenario. You return the Box, which has a pointer to heap allocated memory, as value.
If you do not allocate memory on the stack you can return references to the result which already lives in memory.
In Rust it is efficient to return by value, as the value is moved, not copied.