How is the linear regression cost function evolved?
What I remember is that they give you more insight in future lectures, but the main reason for that is the maximum likelihood with which you try to increase the chance of making the current data set by setting the parameters. It is a good choice for setting the parameters, but its weakness is that it may overfit to your training data. You may want to take a look at Maximum Likelihood Estimation.

The cost function which is discussed there is called minimum square errors. It is found by maximum likelihood. This means that you want to increase the chance of making your training set. In other words, you want to increase the chance of $P(D|\theta)$ where $D$ can be considered as your training set. Due to the fact that your data should be iid, you can write the previous probability as $\pi p(x_i|\theta)$. You then apply some simplifications and you finally find that cost function. You can take a look at MSE as Maximum Likelihood for exact justification.