TL;DR: From the point of view of the national accounts, when someone buys a house, they're not doing it as a member of a household, they're doing it as (and this is a direct quote as highlighted below), "unincorporated enterprises that produce housing services that are consumed by the household to which the owner belongs."
After earlier proposing to close, I now see from other answers and comments that this area is broadly misunderstood, and you thus obviously have a good question here.
From your question, I can see that you understand the conceptual distinction between enterprises, which definitionally invest and produce, and do not consume (as all their purchases are considered to be intermediate inputs to production), and households, which definitionally consume and do not invest or produce.
In this view, it's easy to see why you'd wonder why we carve out the purchases of residential structures and treat them differently.
The answer is that we don't actually treat them differently from the view of the national accounts, because we've created an accounting fiction that treats a person who owns their own home both as an enterprise and as a household. This has been encoded from the start; it appears even in the first System of National Accounts, the international framework for national accounting.
Importantly, it is not, as one of the other answers states, just a convention, just because homes create housing services. If that were the case, we'd also treat other consumer durables, like cars and appliances as investments, but we don't, as you correctly point out in your comments.
Rather, it's done for a very specific reason, which is that if we didn't create this accounting fiction, then comparisons between countries or over time could be distorted by differences in the homeownership rate.
Let's imagine that we stuck with the straightforward approach, which would be to treat all purchases by households as consumption, and treated houses just like we treat cars.
If we did this, then GDP in Japan, for example, would be artificially higher than GDP in the US, because the US has a higher homeownership rate, and conversely, more households in Japan are renters— and rent payments definitely belong in GDP. So just because the same thing (a house) was owned differently in different countries, GDP would differ. We wouldn't want that.
Worse yet, consider a house that was built before the financial crisis and sold (and thus counted in GDP as consumption). Now imagine that the homeowner was unable to make their mortgage payments, and the house was foreclosed on and sold to an investor, who rented it out. The house, already counted in GDP at its initial sale, would then be counted in GDP as a rental, artificially inflating GDP in the aftermath of a financial crisis. We wouldn't want that, either.
The Accounting Fiction
The solution to this, as I mentioned before, has been explicitly accounted for in the System of National Accounts since its first version in 1953. This SNA makes clear the distinction you make between enterprises and households, saying
In other words the production boundary is drawn by first separating households from enterprises and then separating two types of purchases by enterprises, namely those which are and those which are not charged to current cost.
The SNA then goes into the case of primary producers (i.e., farms, etc.), which are in many ways similar, as they're households, but they produce something (food, rental services), which may be consumed by them or by others (if they sell some of what they grow or take in a tenant on an informal basis). The SNA then proposes that farm households be treated both as households and as enterprises:
For instance, farm households are not only households from the consuming point of view but also enterprises which engage in agricultural production.
It goes on to draw a parallel with homeownership:
The farming imputation [note: counting farm production for own use in GDP] made for such economies accords with the rules given for primary producers and the rental imputation [note: counting in GDP what homeowners would be paying in rent if they were renting] accords with the rules given for other producers if account is taken of the face that home-ownership is a regarded as a trade.
This is then encoded in the definition of enterprises:
ENTERPRISES include all firms, organizations and institutions which produce goods and services for sale at a price intended approximately to cover the cost of production. The class of enterprise includes the following categories:
(b) All households and private non-profit institutions in their capacity as landlords of dwellings whether or not they occupy their own properties.
In short, we divide households that own their own homes into two entities: the household as such, and the person who bought the house as a landlord. This is made even more clear in the most recent version (2008):
Persons who own the dwellings in which they live are
treated as owning unincorporated enterprises that produce
housing services that are consumed by the household to
which the owner belongs. The housing services produced
are deemed to be equal in value to the rentals that would be
paid on the market for accommodation of the same size,
quality and type. [...]
The imputed values of the housing services are recorded as
final consumption expenditures of the owners.
How this affects investment
So now we understand that people who purchase homes are being treated as enterprises, rather than households, and then renting the house to the household to which they belong.
From here, the relationship should be straightforward. Because homeowners are enterprises, it's not inconsistent to treat the purchase of the asset as an investment, it's perfectly appropriate.
Further, it should be obvious that doing it any other way would complicate comparisons between countries and over time, the same way that not imputing rent would. If we counted homes that were purchased as consumption, we'd be measuring much lower investment in countries just because they had higher homeownership rates. Similarly, in cities, it's not at all uncommon for apartment buildings that were constructed with rentals in mind to be sold as condos, or vice versa, depending on changes in funding and local market conditions. You wouldn't want measured investment to rise or fall because of this.
There are two quick further implications that are worth touching on:
(1) The full purchase price of a home is not to be counted as investment, only the structure is. Per the BEA:
In the NIPAs, private investment in new construction
is measured mainly as the sum of the costs of inputs
of all construction “put in place,” that is, all
construction activity completed in a given period.
Obviously, this means in part that the land that the house is build on is not counted in GDP, either as investment or construction, as it's just a transfer.
More importantly, though, it's also supposed to exclude consumer durables unless the home is rented— because a refrigerator shouldn't count as an investment when it comes with a home but not when you're replacing it later on.
(2) It's possible to imagine other items, like cars, being treated like houses in the future. If the companies that are trying to build fleets of driverless cars manage to take a larger bite out of private car ownership, we'll have the same issue with cars that we do with homes, where measured GDP and investment over time would be significantly affected by the share of cars that were owned vs. rented (this is already something of an issue due to motor vehicle leasing). We'd see more recorded investment because the cars were owned by enterprises, and we'd see lower volatility in GDP, because every convert to driverless cars would be someone not being recorded as making an all-at-once consumption purchase, instead showing up as a consumer of a stream of services over time.