Consider the supply and demand factors (in addition to other points)
From an institutional viewpoint, it is attractive for universities to "try before you buy". If they can hire staff on a time-limited contract then it is usually possible to successfully renew them or move them into permanent positions if that is desirable. However, if they want to get rid of a staff member in a permanent position then that is more difficult and costly. Consequently, the time limitation in the employment contract can be seen primarily as a clause that favours the interests of the university.
Other answers have pointed out a range of factors relating to the conduct and funding of university research that make it desirable (from the university's point of view) to use time-limited contracts for postdocs and other junior academic staff. These are all good points, but they don't really get to the root of why universities are able to successfully enforce their desires in the employment market, when this imposes serious costs/problems on employees. My view is that this is largely a result of the supply and demand dynamics of our modern education system, where we churn out PhDs at a high rate.
Setting aside very recent events, there is an abundance of PhD graduates relative to the number of available postdoc and academic positions, so universities can impose employment conditions that are not especially desirable for postdocs and still get plenty of good applications. (There have been some recent reports that "the great resignation" has limited this, but we'll see.) This is just one manifestation of the general economic principle that if you increase the labour supply in an industry then (ceteris paribus) the wage/conditions for employees in that industry will fall.