In those days Hezekiah was sick and near death. And Isaiah the prophet, the son of Amoz, went to him and said to him, "Thus says the Lord: 'Set your house in order, for you shall die, and not live.' "
Context
This line is written by Jeremiah in 2 Kings 20:1.
King Hezekiah is sick, and Isaiah comes to let him know that he's a goner, so he'd better get his affairs in order, and prepare to die.
Where you've heard it
Setting your house in order just means making sure everything is in ship shape. You hear this quote applied to organizations a lot. Leaders need to set their house in order after a scandal, a catastrophe, etc.