What's wrong with this code?

Why?
No, it is not necessary. There is no such rule. Any function has a specification what kind of values it can return. If it explicitly says that null can be returned among other values, than you must test it for null, otherwise there is no reason to do that.
For example:
https://en.cppreference.com/w/cpp/io/c/fopen
“On error, returns a null pointer.”

https://en.cppreference.com/w/cpp/io/c/tmpnam
“If no suitable filename can be generated, a null pointer is returned.

Check this out:
https://en.cppreference.com/w/cpp/memory/new/operator_new
“Return value:
1-4) non-null pointer to suitably aligned memory”
Note that 1-4 overloads of operator new can not return null pointer ever. It can fail, but it will not return a null pointer.

“5-8) non-null pointer to suitably aligned memory of size at least size , or null pointer on allocation failure
And in case of 5-8 overloads it returns null pointer on failure. It explicitely sais so.

Now let’s check SpawnActor documentation:

Not a word regarding returning a null value.

Let’s check another place:

“This function creates a new instance of a specified class and returns a pointer to the newly created Actor.”
Again, nothing regarding returning a null value.

I could not found any documentation or official guide that explicetely sais that SpawnActor can return a null pointer. It doesn’t necessarily mean it can not, because Unreal Engine has quite poor documentation. But you can not design your code assuming that any function returning a pointer can return a null value. Your code will be full of unnecessary checks. You can examine Epic’s templates. They never checks returned pointers for null, unless there is an obvious reason.

Anyway, this is a test task for a programmer. A good programmer must follow documentation or official guides, not his best guess, rumors or someone’s complain that SpawnActor returned a null. Right?