It's not so much how as why...
The point of port numbers is to restrict and delimit incoming data which is already available to the system, so it is not that a raw socket has special powers bestowed by the kernel in as much as it the reverse: a normal (i.e., not raw) IP socket has the special power of being specifically addressable.
As an analogy, consider a stained glass window as an IP port numbered socket and a transparent window as a raw socket. It is not that the latter receives more information, it's that it filters out less. The analogy also makes light of the situation in so far as it is not the kernel which creates the situation, it is the physical nature of networking. The kernel does not go out of its way to get the information any more than a window goes out of its way to get sunlight: the sunlight is already there and comes from outside the system.