Why is investment not a cost in firms profit functions? In all textbooks I've seen profits is written as: $$\pi=py-wL-rK$$ It is evident here that w and r are operational costs.

But unless there is no depreciation and the level of capital is to remain fixed, there is a cost of investment! Why is this not taken into account for calculating profits? Is it some sort of assumption of "steady state" involved?
Both in Economics and in Accounting, there is the following fundamental principal: we have to subtract revenues generated in a given time period from costs incurred in the same time period (because this is what makes basic sense).

Now, "cost" is the value of productive resources absorbed into production, in the given time period. The total value of an "Investment" is not absorbed in the usual time period where firms record their profits (month, quarter, year). 
When we buy a machine, we use it for many years. 
So only a part of "Investment" is absorbed in a period (essentially what constitutes an "investment" and what an "(operating) expense" is based on this criterion exactly -whether it is fully absorbed in production in one time period or not). The total value of Investment done in say one year is an outflow in the Cash-Flow statement, but it is not a Cost in the Profit and Loss statement.

And, as you mentioned, that part of the Investment that was absorbed in production during the period, is reflected in the calculated Depreciation, which is chraged as a cost to the Profit and Loss statement.