The government's Bureau of the Census does not say how many illegal aliens there are. This is purely a function of non-official sources, such as Pew. The Census does not ask "are you here legally?'".
Remember, that until the 1920's all immigration was legal with the exception of "Chinese" who were impeded by the very, obscenely, racist legislation prohibiting them dating back to the 1880's. So our census system was never adjusted when it became obvious that some immigrants had entered without authorization.
In theory, the Census counts all persons in the country, legal or not. In fact, the non-English language Census material points this out: "you are not asked your legal status in the USA".
The consensus of demographers is that non-legal residents are counted. The independent demographic sources confirm this; they use data like housing, vehicle registrations, occupied dwelling units, school enrollment, and lots more to estimate population and are generally more accurate than the Census that uses a technology that has been superseded and abandoned in every other area.
However, the law requires a full Census, so we get a centuries old system.