Law professors Anthony Casey and Eric Posner attempt to answer that question in A Framework for Bailout Regulation. Here is the abstract:
During the height of the financial crisis in 2008 and 2009, the government bailed out numerous corporations, including banks, investment banks, and automobile manufacturers. While the bailouts helped end the financial crisis, they were intensely controversial at the time, and were marred by the ad hoc, politicized quality of the government intervention. We examine the bailouts from the financial crisis as well as earlier bailouts to determine what policy considerations best justify them, and how they are best designed. The major considerations in bailing out and structuring the bailout of a firm are the macroeconomic impact of failure; the moral hazard effect of the bailout; the discriminatory effect of the bailout; and procedural fairness. Future bailouts should be guided by principles that ensure that the decisionmaker properly takes into account these factors.