In the $Likelihood$ framework, the different cost functions arise when you take the Maximum Likelihood Estimate of your model parameters given different probabilistic assumptions that describe your situation.
For instance, in the case of fitting a model against measured data:
The squared error stems from the assumption that for the measured data can be modeled as a Gaussian noise added to your model with each datum independent from each other; in this case the optimal cost function when fitting is the summed squared error between each datum and the value of that model at that point. (Sum of squared difference and Gaussian noise model). The absolute error comes from assuming Laplacian noise (https://en.wikipedia.org/wiki/Laplace_distribution)
So the choice of your cost function stems down several factors 1) what is the right probability model that describes your question of interest. 2) what is computationally or algebraically amenable to solve 3) or some combination of 1 and 2.