This is known as a ‘Forward declaration’. It works in this case because the class containing the WhatToSpawn variable doesn’t need to know the size of APickup - it just stores a TSubclassOf-type variable. If you were to have an APickup variable (i.e. not a pointer to one), your class would need to know the size of that APickup object in order to allocate enough space on the stack / in the class.
Any time the size of an object must be known, or methods/variables of that object are going to be accessed, that code must have the full definition of the class, i.e. by including the header file in which the class is declared. As a result, it’s common to forward-declare the class (or struct!) in the header file, and then include the relevant files in the corresponding .cpp file. This means that any other files that include this header don’t also include your Pickup.h file - they have to do it manually, since they don’t pick-up the includes from the .cpp file automatically.
I personally prefer to put a single forward declaration above the class definition, i.e. in your case:
TSubclassOf<APickup> WhatToSpawn; // we don't need to know about the true size of APickup yet, but will probably need more information in the .cpp file
Hope that helps! Try this for further reading.