Why do we consider purchase of house by households as investment? According to what I have read, investment is the expenditure on  creation of capital goods, which means that it is done by producers.

Then why do we treat buying of house by households as investment when they are not doing any production?

In the sense of treating house as investments, we can treat other consumer goods also like investments. For example, if a consumer buys a TV, we could treat that like an investment because he's receiving a benefit for as long as he owns the TV. Why do we treat houses differently?
Definitions:

Investment is the purchase of any (new) capital goods.
A capital good is any good that is used to produce other goods and services.

A house produces a stream of housing services. Hence, a house may be regarded as a capital good. And thus, the purchase of a house may be regarded as investment.

Note though that definitions and lines in economics can often be fuzzy and there can be grey areas. You are quite right to question whether we should count the purchase of a house as investment. One could argue that we shouldn't. However, by convention in national income accounting, we do, with the above as our rationale.
As noted in the UN System of National Accounts (2008, p. 8):

No matter how simple and precise concepts and classifications may appear in principle, there are inevitably difficult borderline cases which cannot easily be fitted into predetermined categories. ...
The general nature and purpose of the distinction between gross fixed capital formation and consumption, whether intermediate or final, is clear. The distinction is fundamental for economic analysis and policymaking. Nevertheless, the borderline between consumption and gross fixed capital formation is not always easy to determine in practice. Certain activities contain some elements that appear to be consumption and at the same time others that appear to be capital formation. In order to try to ensure that the SNA is implemented in a uniform way, decisions have to be taken about the ways in which certain difficult, even controversial, items are to be classified.


In response to an incorrect comment that claims that &quot;The purchase of a new house is not counted as investment&quot;:
BEA glossary:

Consists of purchases of private residential structures and residential equipment that is owned by landlords and rented to tenants.

Blanchard, Macroeconomics (2017, p. A-3):

Residential investment (...) is the purchase of new houses or apartments by persons.

Mankiw, Macroeconomics (2015, p. 27):

Residential investment is the purchase of new housing by households and landlords.

Hubbard &amp; O'Brien, Macroeconomics (2017, p. 255):

Residential investment is spending by households and firms on new single-family and multi-unit houses.